Hello Stallwarts,

I am making a simple VB.net HMI application.
I have dlls which give me functions to read / write registers from PLC / controllers.
Now How do I do this ???
One threads keeps communicating with devices with these read write functions.
Another thread looks after GUI and saving CSV datalog.
Very frequently comm section hangs due to various errors om which we dont have control as these are free dlls .
Now I want to keep these two things separate, even if comm sections stops working , GUI should keep working and make an attempt to kill comm thread and restart it.
Presently as long as PLC communication is OK my app works fine.

Any quick shots at making multithreaded app ??
Thanks and regards,

I wrote an app to monitor a troublesome internet connection. It uses three background threads to monitor three points. I've attached it to this thread and I'd be happy to answer any questions. It's not too complicated and I believe it illustrates some of the things you are trying to do. It still needs a few more comments. I'll update the post if I have time to pretty it up later.

Hello Reverend Jim
I could get good idea how to make threads by going thru your appln.
In your case you get responding = My.Computer.Network.Ping(txtHub.Text) either true or false so that you can process thread further.
But my problem is that my following line hangs indefinetly if external device does not respond. so next code line for try catch or anything else does not execute at all.

ret = ReadSingleReg(comm_type, conn_num, slave_addr, addr, data_from_dev, req, res)
So now how to make timeout thread for this so that within a period of say 100 ms I dont get ret value next statement is executed ?


Here is a simpler example of threading that might be more useful. As for setting a timeout, your background process could update a class level datetime variable such as

lastupdate = Now()

You could have a timer in your main thread which ticks every (let's say) 30 seconds and compares the value of lastupdate to Now() and if the value exceeds a number of seconds that you pick then the timer code could cancel the background thread.

The new code shows how to cancel a background thread and how to get the thread to report progress to the foreground thread. I kind of abuse the Button control but I thought I'd do that rather than clutter up the form with other controls.