KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am creating a custom .net hardware framework that will be used by other programmers to control some hardware. They will add a reference to our DLL to get to our hardware framework. I am in need of a shared class that will be accessed from multiple applications (processes). The singleton pattern seems to be what I need but it only works for multiple threads inside your process. I could be completely wrong but here is an example of the C# code I currently have. I can't help to feel that the design is incorrect. I wish I could share more specific information but I can't. I must stress that I will have no control over the customer application. The solution must be contained inside the framework (DLL) itself. The Framework: (Shared DLL) public class Resources { static readonly Resources m_instance = new Resources(); public string Data; private Resources() { Data = DateTime.Now.ToString(); } public static Resources Instance { get { return m_instance; } } } The Test Application: (eventually customer app) class Program { static void Main(string[] args) { Console.WriteLine("Press enter to capture the resource!"); Console.ReadLine(); var resources = Resources.Instance; Console.WriteLine("\r\n{0}: {1}\r\n", Thread.CurrentThread.ManagedThreadId, resources.Data); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += WorkerDoWork; worker.RunWorkerAsync(); while (worker.IsBusy) { Thread.Sleep(100); } Console.WriteLine("Press enter to close the process!"); Console.ReadLine(); } static void WorkerDoWork(object sender, DoWorkEventArgs e) { var resources = Resources.Instance; Console.WriteLine("\r\n{0}: {1}\r\n", Thread.CurrentThread.ManagedThreadId, reso
Tags (comma-separated)
Save Edits
Cancel