Click here to Skip to main content
15,918,617 members
Home / Discussions / C#
   

C#

 
GeneralRe: Accessing Web Service through HTTP Proxy Pin
Atul Kale15-Apr-03 23:00
Atul Kale15-Apr-03 23:00 
GeneralIDisposable Pin
S O S15-Apr-03 5:45
S O S15-Apr-03 5:45 
GeneralRe: IDisposable Pin
Chris Austin15-Apr-03 6:18
Chris Austin15-Apr-03 6:18 
GeneralRe: IDisposable Pin
Andres Manggini15-Apr-03 6:20
Andres Manggini15-Apr-03 6:20 
GeneralTime Zone Pin
Mazdak15-Apr-03 4:16
Mazdak15-Apr-03 4:16 
GeneralRe: Time Zone Pin
Not Active15-Apr-03 5:07
mentorNot Active15-Apr-03 5:07 
GeneralRe: Time Zone Pin
Chris Austin15-Apr-03 5:09
Chris Austin15-Apr-03 5:09 
QuestionCorrect way to abort a Suspended thread? Pin
Christian Merritt15-Apr-03 3:24
Christian Merritt15-Apr-03 3:24 
I'm using a background thread in my Windows Forms app to retrieve all user objects in our Active Directory. (15,000+ users) I am retrieving users in lots of 1,000, at which time I call the Suspend() method on my thread to pause the GUI and allow them to select a user or users.

If the user presses the Cancel button while the thread is in the running state, I call the Abort() method and catch the corresponding ThreadAbortException, and the thread terminates gracefully.

The problem I'm having is that if I call the Abort() method while the thread is in a suspended state, the thread never terminates. I am catching the ThreadStateException that is thrown, but is there something else I must do to the thread to properly terminate it at this point? Code follows:

private void buttonMemberSelectCancel_Click(object sender, System.EventArgs e)
{
try
{
if (!bgListThread.IsAlive) // is alive?
this.Close();
else
{
try
{
bgListThread.Abort();
}
catch(System.Threading.ThreadAbortException)
{
// abort thread gracefully
}
catch(System.Threading.ThreadStateException)
{
// if suspended, abort gracefully
}
}
}
catch (NullReferenceException)
{
// if thread doesn't exist, just close dialog
}
finally
{
this.Close();
}
}
AnswerRe: Correct way to abort a Suspended thread? Pin
Daniel Turini15-Apr-03 3:47
Daniel Turini15-Apr-03 3:47 
GeneralRe: Correct way to abort a Suspended thread? Pin
Christian Merritt15-Apr-03 3:54
Christian Merritt15-Apr-03 3:54 
AnswerRe: Correct way to abort a Suspended thread? Pin
Martin Cook15-Apr-03 8:26
professionalMartin Cook15-Apr-03 8:26 
GeneralRe: Correct way to abort a Suspended thread? Pin
Christian Merritt15-Apr-03 15:00
Christian Merritt15-Apr-03 15:00 
GeneralRe: Correct way to abort a Suspended thread? Pin
James T. Johnson15-Apr-03 19:47
James T. Johnson15-Apr-03 19:47 
AnswerRe: Correct way to abort a Suspended thread? Pin
Adam Turner15-Apr-03 19:00
Adam Turner15-Apr-03 19:00 
GeneralPrinting from a WebForm in C#/ASP.Net Pin
Vasudevan Deepak Kumar15-Apr-03 1:20
Vasudevan Deepak Kumar15-Apr-03 1:20 
GeneralMaximizing Event (Or Not) Pin
Adam Turner15-Apr-03 0:49
Adam Turner15-Apr-03 0:49 
GeneralRe: Maximizing Event (Or Not) Pin
Srinivasa Raghavan15-Apr-03 1:46
Srinivasa Raghavan15-Apr-03 1:46 
GeneralRe: Maximizing Event (Or Not) Pin
Adam Turner15-Apr-03 18:46
Adam Turner15-Apr-03 18:46 
GeneralGenerating random number of fixed-size Pin
Gerry14-Apr-03 21:45
Gerry14-Apr-03 21:45 
GeneralRe: Generating random number of fixed-size Pin
Nnamdi Onyeyiri14-Apr-03 23:42
Nnamdi Onyeyiri14-Apr-03 23:42 
GeneralRe: Generating random number of fixed-size Pin
Nick Seng14-Apr-03 23:46
Nick Seng14-Apr-03 23:46 
GeneralRe: Generating random number of fixed-size Pin
Nnamdi Onyeyiri14-Apr-03 23:49
Nnamdi Onyeyiri14-Apr-03 23:49 
GeneralRe: Generating random number of fixed-size Pin
Nick Seng14-Apr-03 23:53
Nick Seng14-Apr-03 23:53 
GeneralRe: Generating random number of fixed-size Pin
Nick Seng14-Apr-03 23:43
Nick Seng14-Apr-03 23:43 
GeneralRe: Generating random number of fixed-size Pin
Gerry15-Apr-03 0:15
Gerry15-Apr-03 0:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.