Click here to Skip to main content
15,357,682 members
Home / Discussions / C#
   

C#

 
GeneralRe: Async method/task issue Pin
primem0ver16-Nov-17 10:57
Memberprimem0ver16-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
Memberprimem0ver28-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
Memberprimem0ver2-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
Memberprimem0ver3-Dec-17 1:13 
GeneralRe: Async method/task issue Pin
primem0ver3-Dec-17 1:46
Memberprimem0ver3-Dec-17 1:46 
I suppose this is all easily fixed by removing the "BackgroundWorker.ReportProgress(100)" call in my Task::End() method. I only included this originally because I did a test program to see how the BackgroundWorker operated before building the logic of my "adapter". I wanted to test how the BackgroundWorker dealt with values over 100 because the BackgroundWorker class was designed without taking into consideration that the programmer might not want to report percentage, but rather tasks (such as files being processed etc...). So I built this test program:

C#
namespace BackgroundWorkerTest
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void OnDoWork(object sender, EventArgs e)
		{
			backgroundWorker.RunWorkerAsync();
			backgroundWorker.DoWork += backgroundWorker_DoWork;
		}

		void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
		{
			for (int i = 0; i < 10; ++i)
			{
				for (int x = 0; x < 10; ++x)
				{
					for (int j = 0; j < 1000000; ++j)
					{
						bool b = false;
					}
				}
				backgroundWorker.ReportProgress(500);
			}
			//backgroundWorker.
		}

		private void OnProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			progressBar1.Value += e.ProgressPercentage;
		}

		private void OnWorkComplete(object sender, RunWorkerCompletedEventArgs e)
		{
			MessageBox.Show("Worker Done!", "Worker Message");
		}
	}
}

When I run the test, the "OnWorkComplete" method is called, posting the "Worker Done!" message box long before the DoWork method is completed... indicating to me that the "complete" event is also raised when ReportProgress is called with a value of over 100 (this was the behavior I was testing). I added my line in my "End()" post in order to make sure the "completed" event occurred. Apparently both this and completing the DoWork callback can invoke the "complete" event while only the second scenario shuts the worker down. Again... more terrible design on the part of Microsoft.

EDIT NOTE: The BackgroundWorker in this particular test is connected to the last two handlers by the Designer since the test only uses one worker that I directly tied to the GUI.

modified 3-Dec-17 7:59am.

GeneralRe: Async method/task issue Pin
Gerry Schmitz3-Dec-17 3:17
mveGerry Schmitz3-Dec-17 3:17 
GeneralRe: Async method/task issue Pin
primem0ver3-Dec-17 4:03
Memberprimem0ver3-Dec-17 4:03 
GeneralRe: Async method/task issue Pin
Gerry Schmitz3-Dec-17 4:41
mveGerry Schmitz3-Dec-17 4:41 
GeneralRe: Async method/task issue Pin
primem0ver4-Dec-17 2:12
Memberprimem0ver4-Dec-17 2:12 
GeneralRe: Async method/task issue Pin
Gerry Schmitz4-Dec-17 6:50
mveGerry Schmitz4-Dec-17 6:50 
GeneralRe: Async method/task issue Pin
primem0ver3-Feb-18 23:03
Memberprimem0ver3-Feb-18 23:03 
GeneralRe: Async method/task issue Pin
Gerry Schmitz4-Feb-18 7:05
mveGerry Schmitz4-Feb-18 7:05 
Questionin c# school management project Pin
Member 1289859014-Nov-17 19:51
MemberMember 1289859014-Nov-17 19:51 
AnswerRe: in c# school management project Pin
OriginalGriff14-Nov-17 20:11
mveOriginalGriff14-Nov-17 20:11 
AnswerRe: in c# school management project Pin
Gerry Schmitz15-Nov-17 5:41
mveGerry Schmitz15-Nov-17 5:41 
AnswerRe: in c# school management project Pin
jschell15-Nov-17 7:03
Memberjschell15-Nov-17 7:03 
QuestionDetermine Distance between HD Camera and Object Pin
Member 1041074814-Nov-17 4:09
MemberMember 1041074814-Nov-17 4:09 
AnswerRe: Determine Distance between HD Camera and Object Pin
Richard MacCutchan14-Nov-17 4:51
mveRichard MacCutchan14-Nov-17 4:51 
AnswerRe: Determine Distance between HD Camera and Object Pin
Dave Kreskowiak14-Nov-17 5:24
mveDave Kreskowiak14-Nov-17 5:24 
AnswerRe: Determine Distance between HD Camera and Object Pin
Gerry Schmitz15-Nov-17 5:39
mveGerry Schmitz15-Nov-17 5:39 
Questionmy projects link button not work in iphone 6s but desktop work properly why? Pin
Member 1352056914-Nov-17 2:27
MemberMember 1352056914-Nov-17 2:27 
AnswerRe: my projects link button not work in iphone 6s but desktop work properly why? Pin
Pete O'Hanlon14-Nov-17 3:37
mvaPete O'Hanlon14-Nov-17 3:37 

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.