Windows application gets stuck while using workflow

In my application, I send larger emails (> 2.5 MB). Now, while emails are not being sent, the application is in the hanged up state (the mouse cursor is busy with the state).

One of my friends suggested using a background worker who could "display" a message, for example, "Please wait ... Sending email." I have no idea how to use the background workflow. Please guide me

Or, if there is any other faster / simpler alternative, I would appreciate the inputs

+3
source share
6 answers

If you do not want your user interface to hang, waiting for lengthy processes, you have to use the thread. BackgroundWorker- a good implementation of this method, which allows you to use to track progress, allows the user to interrupt the process, etc.

In the "Stack Overflow" section there are many questions about BackgroundWorkeror check the MSDN documentation .

0
source

You do not want to use a separate process - you want to use a different thread.

, . , .

, , BackgroundWorker. , Control.Invoke Control.BeginInvoke . , , - , , , ( , BackgroundWorker ), EDIT: BackgroundWorker , .

- :

public void SendEmailButtonClicked(object sender, EventArgs e)
{
    // Make any changes to the UI here to disable whatever you want
    new Thread(SendEmail).Start();
}

private void SendEmail()
{
    // Do the sending of the email here (this is in the non-UI thread)

    // Then afterwards, possibly in a finally block
    Action action = EmailSent;
    this.BeginInvoke(action);
}

private void EmailSent()
{
    // Back in the UI thread, do whatever you need to indicate
    // success/failure, re-enable disabled parts of the UI etc
}
+2
+1

Have a look at this thread guide: http://msdn.microsoft.com/en-us/library/aa645740%28v=vs.71%29.aspx

The main idea is that you press the mouse button, create a new stream that will take care of sending the letter.

0
source

All Articles