Multiform multi-process

H

hakan aktan

Hi all,
I have 2 wince forms and fisrst form causes second to launh.While some
process is running on first
I need second form to have a hard process too. I tried thread, timer and
while , they did not work.
The forms are being locked after a few seconds.Is there another way ,i need
anything that works multi processes on multiform.
Here is my code: (Wince 4.2 OS , Coding VB.Net 2003 on CF 1.1)

Thanx in advance
Form1:
'--------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm2 As New Form2

frm2.Show()

'This job has to work until main Form1 is closed

While (True)

Application.DoEvents()

System.Threading.Thread.Sleep(1000)

'Do stg

End While

'Form2 Code

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim th As Thread
th = New Thread(AddressOf mySub)
th.Start()
End Sub
Private Sub mySub()
While(MoveForward)
Application.DoEvents()
System.Threading.Thread.Sleep(300)
'Do stg
Next
End Sub
 
H

hakan aktan

Thanx for your reply Mr Tacke. But i have a little problem about threads.
In my main form ( code below my first mail) , i have a few function that
communicates from
comm1 port sequencely and saves data (comes from ports) to hash tables.
My second form shows these datas from hashtable by graphics by refreshing
every 2 seconds.
Main form must communicate with port until it is closed.
But when i use thread at form1 comm port datas mix and later gives
error.(CFSerial.Dll)
Because my communicate functions tries to work together on 1 port at the
same time when i use thread.
When they lose sequence , comm port locks..
Thanx in advance for any idea about this scenario...
 
D

DJMatty

Hi

I think Chris is right, you need to run a single thread that
communicates with the com port and stores the data in a thread safe
manner.

The main application thread can read the data that is stored by the
worker thread from the serial port and display it.

You can't update form controls from a worker thread as this needs to be
done from the main thread. You can use the BeginInvoke method in your
worker thread to signal to your main thread that controls need
updating.

Have a look at this article.

http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

This is quite interesting too:

http://www.codeproject.com/csharp/begininvoke.asp

It seems that .Net 2.0 checks for cross thread ui updates and throws
exceptions.

Matt
 
G

Guest

No, the main form should *not* be talking with the serial port. That's the
root of your problem. Move your comms to a separate thread, or use
event-based programming instead of polling (which is how the serial classes
are designed anyway).

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top