Threading

  • Thread starter Charles A. Lackman
  • Start date
C

Charles A. Lackman

Hello,

I am making a app that creates a thread to show a clipboard. If the
clipboard is double clicked, another window is displayed, the event is
handled inside the main app. What I would like to do is have the clipboard
use the main thread of the application that called it to handle the new
window. Is this possible and if so how would this be accomplished.


ie.

Form1 creates a thread and the thread displays Form2.

Form2 when double clicked raises an event that creates a new form (Form3).
The event is handled inside Form1.

How can I get Form3 to be managed by the main thread (Form1)?


Thanks,

Chuck
 
H

Herfried K. Wagner [MVP]

Charles A. Lackman said:
Form1 creates a thread and the thread displays Form2.

Form2 when double clicked raises an event that creates a new form (Form3).
The event is handled inside Form1.

How can I get Form3 to be managed by the main thread (Form1)?

Create /all/ forms in the application's main (UI) thread. Only start
"operations" in a separate thread and use
'Control.Invoke'/'Control.BeginInvoke' to communicate in the thread -> UI
direction.
 
R

Robby

Let Form2 create Form3 by using a callback on Form1. This will create Form3
on the Form1 thread.

Robby
 
C

Charles A. Lackman

Hello and thank you for your assistance.

I have attempted to accomplish what I need using delegates with no success.
i.e.

//Button Click//
Dim PollThread As Threading.Thread
PollThread = New Threading.Thread(AddressOf PollThreadAddress)
PollThread.Start()
End Sub

Private Sub PollThreadAddress()
frm1PollDatabase.TopMost = True
frm1PollDatabase.ShowDialog()
End Sub

//Button Click inside frm1PollDatabase that raises an event inside the
Parent Form//
Delegate Sub FromMyPage()
Dim MyDeleg As FromMyPage

Private Sub ApplyMyPage
MyDeleg = New FromMyPage(AddressOf DelegateFromMyPage)
MyDeleg.Invoke()
End Sub

Private Sub DelegateFromMyPage()
frm1Modify.showdialog
End Sub

** frm1PollDatabase is created inside a new thread and must always be on
top, which works fine. But when the user wants to send that data from this
form to a new form (frm1Modify) the form is displayed but frm1PollDatabase
becomes disabled because of the Showdialog method. I cannot use show for
this form to be displayed. If the original thread (Main) displays this form
wont it prevent this problem? The above code did not keep frm1PollDatabase
from being disabled.

Thanks Again,
Chuck
 
R

Robby

Instead of threading could you just show as a normal top most form? When
the selection is made on frm1PollDatabase raise an event on the main form.
You could then create frm1Modify on the main form, fill it with the
properties needed from frm1PollDatabase, destroy frm1PollDatabase and then
show frm1Modify. Now the main form and frm1Modify are on the same thread
and can communicate easily while they do their own processes. This seems to
do the trick without all the unecessary threading.

Is there any reason why you have to thread?

Robby
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top