Click here to Skip to main content
15,891,473 members
Home / Discussions / C#
   

C#

 
GeneralRe: Active Directory Questions Pin
Kevin Marois17-Nov-17 4:39
professionalKevin Marois17-Nov-17 4:39 
AnswerRe: Active Directory Questions Pin
Nathan Minier17-Nov-17 1:36
professionalNathan Minier17-Nov-17 1:36 
Generalsession Pin
Ishi Kaushik16-Nov-17 7:04
Ishi Kaushik16-Nov-17 7:04 
AnswerRe: Hello , I am working on three tier architecture based project, i am stuck in writting session code. so please tell me how and where i can write the session code Pin
OriginalGriff16-Nov-17 8:03
mveOriginalGriff16-Nov-17 8:03 
QuestionData type mismatch in criteria expression." in c# Pin
sai.201216-Nov-17 5:54
sai.201216-Nov-17 5:54 
AnswerRe: Data type mismatch in criteria expression." in c# Pin
Gerry Schmitz16-Nov-17 6:35
mveGerry Schmitz16-Nov-17 6:35 
AnswerRe: Data type mismatch in criteria expression." in c# Pin
Eddy Vluggen16-Nov-17 7:07
professionalEddy Vluggen16-Nov-17 7:07 
PraiseRe: Data type mismatch in criteria expression." in c# Pin
sai.201216-Nov-17 9:56
sai.201216-Nov-17 9:56 
GeneralRe: Data type mismatch in criteria expression." in c# Pin
Eddy Vluggen16-Nov-17 10:33
professionalEddy Vluggen16-Nov-17 10:33 
QuestionLicensing a .NET DLL Pin
P.Gnanaraj16-Nov-17 2:17
P.Gnanaraj16-Nov-17 2:17 
AnswerRe: Licensing a .NET DLL Pin
Richard MacCutchan16-Nov-17 3:20
mveRichard MacCutchan16-Nov-17 3:20 
QuestionAsync method/task issue Pin
primem0ver15-Nov-17 7:21
primem0ver15-Nov-17 7:21 
AnswerRe: Async method/task issue Pin
Sascha Lefèvre15-Nov-17 8:33
professionalSascha Lefèvre15-Nov-17 8:33 
GeneralRe: Async method/task issue Pin
primem0ver15-Nov-17 9:52
primem0ver15-Nov-17 9:52 
GeneralRe: Async method/task issue Pin
Sascha Lefèvre15-Nov-17 10:19
professionalSascha Lefèvre15-Nov-17 10:19 
AnswerRe: Async method/task issue Pin
Gerry Schmitz16-Nov-17 4:24
mveGerry Schmitz16-Nov-17 4:24 
GeneralRe: Async method/task issue Pin
primem0ver16-Nov-17 10:57
primem0ver16-Nov-17 10:57 
GeneralRe: Async method/task issue Pin
Gerry Schmitz16-Nov-17 11:13
mveGerry Schmitz16-Nov-17 11:13 
GeneralRe: Async method/task issue Pin
primem0ver28-Nov-17 13:41
primem0ver28-Nov-17 13:41 
GeneralRe: Async method/task issue Pin
Gerry Schmitz29-Nov-17 4:29
mveGerry Schmitz29-Nov-17 4:29 
GeneralRe: Async method/task issue Pin
primem0ver2-Dec-17 13:30
primem0ver2-Dec-17 13:30 
GeneralRe: Async method/task issue Pin
Gerry Schmitz2-Dec-17 13:46
mveGerry Schmitz2-Dec-17 13:46 
GeneralRe: Async method/task issue Pin
primem0ver3-Dec-17 1:13
primem0ver3-Dec-17 1:13 
Ok. But I have already done all that. The UI class that manages the worker (the "adapter" as you say) is the same custom control class that manages the tasks (represented by the "Task" class) and displays progress. It has a method "AddTask" that sets up the background worker like this:

C#
public void AddTask(Task task) 
{ 
	tasks.Add(task); // tasks is a List<Task> object
	counterText = counterTemplate.Replace("#2", tasks.Count.ToString());
	task.BackgroundWorker.WorkerReportsProgress = true;
	task.BackgroundWorker.ProgressChanged += OnTaskProgressChanged;
	task.BackgroundWorker.RunWorkerCompleted += OnTaskCompleted;
}

(The DoWork event handler is set up in the Task class constructor so it has already been assigned by the time the above method is called). Assuming by "completed" you are referring to the RunWorkerCompleted event, as you can see, I have a handler (shown below). That handler makes it so that the BackgroundWorker method for the task is set to null (by calling the task's "InvalidateWorker" method also shown below). This handler is NOT being called before the Task::End() code I posted above.

The OnTaskCompleted method (part of the custom control with the AddTask method above):
C#
void OnTaskCompleted(object sender, RunWorkerCompletedEventArgs e)
{
	tasks[currentIndex].InvalidateWorker(); // break point on this line
	NextTask();
}

The InvalidateWorker() method in the Task class (I suppose I could dispose the BackgroundWorker here if necessary):
C#
public void InvalidateWorker()
{
	BackgroundWorker = null;
}

I have a break on the line where the OnTaskCompleted method calls the InvalidateWorker method that is not reached before the End method I posted previously is called (from the OnTaskProgressChanged method if the UI detects that the progress bar has reached its last step). So I am having a hard time understanding why the background worker is "completing" without invoking the event handler for it. I am also assuming that because it is "busy" it hasn't officially completed the call.

The only explanation I can think of is that the "completed" message is queued in the message queue/loop behind the "progress" message that detected the work was technically completed and that the background worker is shut down before "completed" event is invoked. If so, that is just bad design on the part of Microsoft. I figured though that the "IsBusy" would indicate that this is the case (see my End() method in the previous post); but apparently that isn't the case either... which makes Microsoft's code even worse.

modified 3-Dec-17 7:28am.

GeneralRe: Async method/task issue Pin
primem0ver3-Dec-17 1:46
primem0ver3-Dec-17 1:46 
GeneralRe: Async method/task issue Pin
Gerry Schmitz3-Dec-17 3:17
mveGerry Schmitz3-Dec-17 3:17 

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.