?
Solved

Sharing the same State object

Posted on 2009-12-23
7
Medium Priority
?
260 Views
Last Modified: 2013-12-17

I am new to this feature of WinForms and don't exactly know where to start. I have this link but don't quite get it.

http://msdn.microsoft.com/en-us/library/system.runtime.remoting.aspx

If someone cold please give me a quickl overview of using a shared state object I'd appreciate it.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 4
  • 3
7 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 26115894
Can you clarify what "sharing" means to your app?
If shared a State object:
- Among threads you do not need remoting.
- Among other programs on the same PC (Yes remoting is an option in .nwt 2.0 - it is obsolete in 3.0 because it is done with WCF)

http://www.beansoftware.com/NET-Tutorials/NET-Remoting-Tutorial.aspx
http://quickstart.developerfusion.co.uk/quickstart/howto/doc/Remoting/singleton.aspx
0
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 2000 total points
ID: 26115916
If you go the WCF way:
http://www.wcftutorial.net/Singleton-Service.aspx
http://www.wcftutorial.net/WCF-Development-Tools.aspx

The reason I suggest to use a singleton is because you are sharing the same object across multiple applications
0
 

Author Comment

by:newbieweb
ID: 26115922
Both programs are single threaded. I use .NET 2.0 and would be willing to adopt an "old" technology, since it's newer than my alternative method of communicating: text files.

I need to create a Health Check for my main program, where if it's stopped more than 10 seconds, a utility program sends out a text message.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 2000 total points
ID: 26116045
If your issue is only to communicate messages  you can use TCP client/server communication, just make one of the programs the server and the other the client. You do not need the complexity of remoting.
http://www.codeproject.com/KB/IP/BasicTcpServer.aspx
http://www.java2s.com/Code/CSharp/Network/TCP-Server.htm

You need remoting only if you want to share the object fields and state as such, then you need to check the samples on the links posted before.
http://www.beansoftware.com/NET-Tutorials/NET-Remoting-Tutorial.aspx
http://quickstart.developerfusion.co.uk/quickstart/howto/doc/Remoting/singleton.aspx
0
 

Author Comment

by:newbieweb
ID: 26118911
Looking at the demos, even TCP looks complicated. How about using WCF?

It is something I'd love to learn about and start to use.

Haw hard can that be?!
0
 

Author Comment

by:newbieweb
ID: 26119077
Actually, THE PROBELM is that I can not figure out the simplest logic using the text file. I need to deploy this tonight, and the text file method is fine for now. But I can not figure out the silly time stamp logic.  Here's what I have:

A TLDatetime object is my wrapper for a DateTime, but can be null. The form has a checkbox to enable the Health Check and an edit field for the seconds of delay to allow. RaiseAlarm() only gets called when the time limit has elapsed. But this code isn not working.

Can you see why?

        private void PerformHealthCheck()
        {
            if (form.HealthCheck)
            {
                TLDateTime timeLimit = new TLDateTime(lastTouchedTime);
                timeLimit.AddSeconds(form.HealthCheckDelay);
                bool fileExists = Utils.FileExists(Configuration.DataDir + "DriverUpHealthCheck.LOG");

                TLDateTime newTouchedTime = null;
                if (fileExists)
                {
                    newTouchedTime = Utils.GetLastModifiedTime(Configuration.DataDir + "DriverUpHealthCheck.LOG");
                    if (newTouchedTime.CompareTime(timeLimit) < 0)
                    {
                        return;
                    }
                    lastTouchedTime = newTouchedTime;
                }
                RaiseAlarm();
            }
        }


0
 

Author Closing Comment

by:newbieweb
ID: 31669610
Text files work for now. Thanks for the help.

newbieweb
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question