Re: Initialize form controls based on serial port data

You have a serialport handling method. Ok. What does that have to do with your database or your users?

Quote

How can I now pass the value read from DataReceivedHandler to the reinitialise method and start the application?

What? The application is already started. Otherwise how would you have anything?

Are you saying the user name is being passed through the serial port?
So the user name comes in via serial ("bob456") for example, and you want to pass that to your ReInitialise() method? Raise an event in your serial port handler instance. Pass the text. Put in a string parameter in your ReInitialize() method.

Basically you're asking "I've cobbled together this stuff from various internet sources but don't know how to actually design the program. Can someone here take all the parts I've found and make a working program?"

Most of us aren't going to design your program for you. Or put all this found data together into a working program for you.

These tutorials should help you with the events and designing your app.

Re: Initialize form controls based on serial port data

Re: Initialize form controls based on serial port data

Posted 16 August 2012 - 07:29 AM

After yesterday's post, I sat down and thought what made serial port to function differently in console and WPF application. Answer lay in WPF threading model. In console application main thread and serial port thread are synchronised whereas in WPF , main application thread(primary) and serial port (secondary) thread are different. We need to use dispatcher invoke method so that serial port thread can send information to main application.

Re: Initialize form controls based on serial port data

Posted 16 August 2012 - 07:41 AM

This might be an unpopular answer but I see that has a hack most times.
When you have to use Dispatcher.Invoke like that it is most often used as a way to bypass the fact that you're directly changing things across threads - rather than fix the logic so each thread properly takes care of its own responsibilities.

Personally, I would make a UserControl that handles your COM ports. Have it raise an event for whatever you want such as NewUserEvent with a NewUserEventArgs that carries the data of the user's credentials/name/login. The extra 30 minutes of coding up front to make a proper design will save tons of headache and more patching for the lifespan of the product.