Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a project that runs in its own thread
Message
From
21/08/2008 10:19:25
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01340388
Message ID:
01340751
Views:
7
Hi Paul,

>>Thanks for your response as always. I may have to make some changes to the way I am doing this since I am using a singleton on this class. I probably don't need to since I now have a application property to get access. Here is my code now. Then to access this I just instantiate the class and call the MainEntry and that puts everything else into a seperate thread?
>
>
>Pretty much. MainEntry() creates the new thread and does a callback into that same class, except it's running on a new thread. Just be aware that if you've got callbacks, events, etc. that they may not be happening on the thread you expect them to. Also, uncaught exceptions will kill the process, so you may want to wrap this stuff in a try/catch.
>
>BTW - you can view what thread is currently active in the VS debugger. Depending on how VS is configured you may see it under View > Other Windows > Threads. In my case it wasn't originally there so I had to go into Tools > Customize > Commands > Debug > Threads and drop it onto the menu where I wanted it to appear. Then you can open another window which shows you the active and current threads.

The events are the thing I am not clear on. Since I am connecting to an external device via its own Dot NET API I am subscribing to events in this class and handleing them here only. Also since it is a wrapper class I have defined my own events inside this class and am raising them as needed and subscribing to them in my application classes. Will this be an issue for me this way?

Thanks for the help, I very much appreciate it. Somehow I always dumbly thought a seperate assembly would just always run in its own thread. Apparently not thought out, but glad I am getting this sorted out now.

In order to prevent CrossThread Exceptions I use Invoke on my handler methods like this:
/// <summary>
/// Rfid TagAdded Handler
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">TagAddedEventArgs</param>
private void rfid_TagAdded(object o, TagAddedEventArgs e)
     { this.Invoke(new TagAddedDelegate(OnTagAdded), new object[] { o, e }); }
private void OnTagAdded(object sender, TagAddedEventArgs e)
{
	this.txtCurrentRead.Text = this.StripLeadingZeros(e.TagAsString);
	if (e.HasError)
		this.txtCurrentRead.Text += " *";
	}
}
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform