473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Shut down thread - thread closes form, form doesn't close because thread calls it etc...


Some thread confusion to lighten up your day:

I have a worker thread and a main form. When the user clicks the Close icon
in the top right of the form, my program tells the thread to "stop". The
thread will then complete its current operation and "Invoke" a method on the
form telling it it has completed. The completed handler then calls Me.Close
(). The trouble is, I seem to have some deadlock here - I mean after I call
Me.Close(), does the form exit the method, return to the thread etc.?

How exactly can a worker thread shut down the form that created it!???

Any ideas?
Cheers
Robin
Nov 20 '05 #1
4 1662
Its ok, nobody panic. I solved this one with an asynchronous call to the
main thread and a bit of fiddling about :)

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:bm*******************@news.demon.co.uk...

Some thread confusion to lighten up your day:

I have a worker thread and a main form. When the user clicks the Close icon in the top right of the form, my program tells the thread to "stop". The
thread will then complete its current operation and "Invoke" a method on the form telling it it has completed. The completed handler then calls Me.Close (). The trouble is, I seem to have some deadlock here - I mean after I call Me.Close(), does the form exit the method, return to the thread etc.?

How exactly can a worker thread shut down the form that created it!???

Any ideas?
Cheers
Robin

Nov 20 '05 #2
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my face
has been flushed and my mind's been all of a dither. I can calm down now!!
Aaaaahh. ;-))

Regards,
Fergus
Nov 20 '05 #3
Hi Fergus,

Can you point me to a tutorial that will allow me to share controls among
threads? I am able to do datasets and such as long as I dont use them in the
primary thread but I would like to learn how to use controls otherwise if I
can.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my face has been flushed and my mind's been all of a dither. I can calm down now!!
Aaaaahh. ;-))

Regards,
Fergus

Nov 20 '05 #4
You just need to use Delegate and the controls "Invoke" method. This will
ensure that the control method is executed on the controls thread, not the
thread making the call. Like this:

Here is a delegate, representing a method on my main form (doesn't matter
what it is, could be anything really) - this delegate is defined in my
thread.

Private Delegate Sub _onBeginNodeOperations_Delegate(ByVal nAdding As
Integer, ByVal OperationType _
As OperationsThreadState.NodeOperations, ByVal bIsUndoRedo As
Boolean)

Now, the thread wants to execute the delegate method on the main form
thread, not the current thread, so:

Try

m_Form.Invoke(New _onBeginNodeOperations_Delegate(AddressOf
m_Form.BeginNodeOperations), Parameters)

Catch ex As Exception

End Try
"scorpion53061" <sc************@yahoo.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Hi Fergus,

Can you point me to a tutorial that will allow me to share controls among
threads? I am able to do datasets and such as long as I dont use them in the primary thread but I would like to learn how to use controls otherwise if I can.

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Oc**************@TK2MSFTNGP12.phx.gbl...
Hi Robin,

Praise be that you've solved it!!. My heart's been pounding and my

face
has been flushed and my mind's been all of a dither. I can calm down now!! Aaaaahh. ;-))

Regards,
Fergus


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jdph40 | last post by:
I am using Access 2002. I downloaded the forms sample database FrmSmp97.mdb from Microsoft and used the following code in the timer event of a hidden form in order to close a database if no...
8
by: Tim Bücker | last post by:
Following scenario: The user opens a form, a thread is started to play a sound ... public void playSoundUsingThread() { if (File.Exists(fileLocation)) PlaySound(fileLocation, 0, 0); //...
4
by: Claire | last post by:
Running XP pro, SP2. Visual studio .NET 2003. App written in C# I have written an application that hides itself when run and shows a notification icon in the system tray. If the main form is...
2
by: MuZZy | last post by:
HI, As i posted below i have an app with a separate thread listening for a tcp client connection. In the simplest way it looks like: void ListenerThreadFunction() { TcpListener l = new...
1
by: mikelostcause | last post by:
Is there anyway to hold the base.WndProc(ref m) until after the Logout() function finishes loading a webpage?? I'm working on shutting down an app that runs in the system tray, I have no...
4
by: pamelafluente | last post by:
Hi Guys, I have a small application which uses a NotifyIcon. The user can set a flag (PreventClosing ) so that when he clicks on the form-cancel button "X", the program will instead be...
23
by: Chukkalove | last post by:
Im sorry, I dont know the correct description for a hierarchy of parent and child forms. I have a main form that opens a child form modally. This child form in turn opens it's own child form...
1
by: TC | last post by:
I'm confused about the proper way to shut down my application. I have a form which instantiates a control, which instantiates another control, which instantiates yet another control that runs a...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.