HOWTO stop an event with another event 
Author Message
 HOWTO stop an event with another event

Hi,

Here is a problem in my current project ...

I have two buttons, cmdStart and cmdCancel. Pressing
cmdStart will send a file to a remote server.

Suppose after user presses "start", the user wants to stop
this work by pressing "cancel".

To achieve this purpose, what should I put in
cmdCancel_Click(object sender, System.EventArgs e)?

Thanks in advance,
Jason



Fri, 06 Aug 2004 09:19:19 GMT  
 HOWTO stop an event with another event
How do you send the File to the Other Machine, A Socket?

Quote:
> Hi,

> Here is a problem in my current project ...

> I have two buttons, cmdStart and cmdCancel. Pressing
> cmdStart will send a file to a remote server.

> Suppose after user presses "start", the user wants to stop
> this work by pressing "cancel".

> To achieve this purpose, what should I put in
> cmdCancel_Click(object sender, System.EventArgs e)?

> Thanks in advance,
> Jason



Fri, 06 Aug 2004 10:31:32 GMT  
 HOWTO stop an event with another event
First of all, you need to free up the main thread. This thread is used to
check the message queue, which is where the OS puts information like what
button was just pushed.

You have two options...

1. Call DoEvents on a regular basis. This hijacks the current thread and
uses it to check the message queue for OS-triggered events. If any events
are found, they are executed in order.

2. Have the Start button create a secondary thread. This thread would handle
transferring the data, allowing the main thread to concentrate on the GUI
and OS-triggered events.

The Cancel button should set a variable to False.

The Send File function must check this variable on a regular basis. When it
changes from True to False, the function should terminate itself.

--
Jonathan Allen

.Net Wish List Site: http://jonathan.cloverlink.com/


Quote:
> Hi,

> Here is a problem in my current project ...

> I have two buttons, cmdStart and cmdCancel. Pressing
> cmdStart will send a file to a remote server.

> Suppose after user presses "start", the user wants to stop
> this work by pressing "cancel".

> To achieve this purpose, what should I put in
> cmdCancel_Click(object sender, System.EventArgs e)?

> Thanks in advance,
> Jason



Fri, 06 Aug 2004 10:08:47 GMT  
 HOWTO stop an event with another event
P.S. Please don't use "HOWTO" in the subject lines. Just "stop an event with
another event" is enough. If everyone used "HOWTO", then every message would
be sorted under the H's, which is just annoying.

--
Jonathan Allen



Fri, 06 Aug 2004 10:13:00 GMT  
 HOWTO stop an event with another event
Ok you can call the Close Method in the TcpClient:
Example:
public class test
{
    private TcpClient remote;
    public test() {}
    private void Send(object sender, ...)
    {
        //Send the File.
    }
    private void Cancel(object sender, ...)
    {
        MessageBox.Show("Are You sure?",.....)
        if (// MessageBox == yes)
        {
              remote.Close(); //This can help, but if you like, you can send
a message in another thread to the Server App, A Delete File Command
        }
    }
Quote:
}



Quote:
> I use TcpClient in my project. But Socket also can do that.

> Jason

> >-----Original Message-----
> >How do you send the File to the Other Machine, A Socket?



Fri, 06 Aug 2004 15:34:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Event handle as private member stops event firing.

2. HOWTO: Handle the Closed event in a C# UserControl

3. Stop Move Event

4. stopping a close form event

5. HOWTO capture ATLsxWin events

6. Howto select events from a connection point?

7. ATL Service - Sporadically does not report SERVICE STOP in event log

8. Atl Dll events stop in VB IDE after error triggered

9. How to catch the Stop/Back/Forward events in IE

10. HOWTO sink events

11. Pb: howto intercept show/hide/close event in CToolBar

12. Handling key events within views: howto?

 

 
Powered by phpBB® Forum Software