示例#1
0
        // timer tick (update states)

        // dataloader related events
        private void DataLoader_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.UserState != null)
            {
                BGWResult result = (BGWResult)e.UserState;
                Debug.WriteLine("Progress: " + e.ProgressPercentage + " | " + result.Msg);

                w_InfoLbl.Content = e.ProgressPercentage + "% : " + result.Msg;
            }
        }
示例#2
0
        private void DataLoader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Classes.Util.ShowCallInfo();
            if (e.Cancelled || (e.Result != null && ((BGWResult)e.Result).Error))
            {
                Debug.WriteLine("Dataloader was cancelled!");

                if (e.Result != null)
                {
                    BGWResult result = (BGWResult)e.Result;
                    w_InfoLbl.Foreground = Brushes.Red;
                    w_InfoLbl.Content    = result.Msg;
                    mLoadingError        = true;
                }
            }
            else
            {
                mLoadingDone = true;
            }
        }
示例#3
0
        private void DataLoader_DoWork(object sender, DoWorkEventArgs e)
        {
            Classes.Util.ShowCallInfo();
            BackgroundWorker worker = sender as BackgroundWorker;

            string[] files = e.Argument as string[];

            FileInfo[] fi          = new FileInfo[files.Length];
            long       fileSizeSum = 0;

            for (int i = 0; i < files.Length; i++)
            {
                fi[i] = new FileInfo(files[i]);
                if (fi[i].Exists)
                {
                    fileSizeSum += fi[i].Length;
                }
            }

            for (int i = 0; i < fi.Length; i++)
            {
                // check cancellation
                if (worker.CancellationPending)
                {
                    Debug.WriteLine("Dataloader cancel!");
                    e.Cancel = true;
                    return;
                }

                if (fi[i].Exists && fi[i].Length > 0)
                {
                    // TODO: process file data
                    for (int j = 0; j < 1000000; j++)
                    {
                        for (int k = 0; k < 500; k++)
                        {
                            double a = Math.Sqrt(25);
                        }
                    }
                }

                string    fileDone = fi[i].Name + " " + (fi[i].Exists ? "is loaded" : "not found");
                BGWResult report   = new BGWResult(!fi[i].Exists, fileDone);
                worker.ReportProgress((i + 1) * 100 / fi.Length, report);

                if (!fi[i].Exists || fi[i].Length <= 0)
                {
                    // set error when file is not found
                    Debug.WriteLine("Dataloader cancel because error!");
                    //e.Cancel = true;
                    e.Result = new BGWResult(true, "File not Found: " + fi[i].FullName);
                    return;
                }
            }

            //const int OUTER_LOOP = 250;
            //for (int i = 0; i < OUTER_LOOP; i++)
            //{
            //	for(int j = 0; j < 10000000; j++)
            //	{
            //		if (worker.CancellationPending)
            //		{
            //			Debug.WriteLine("Dataloader cancel!");
            //			e.Cancel = true;
            //			return;
            //		}

            //		double a = Math.Sqrt(25);
            //	}

            //	worker.ReportProgress(i * 100 / OUTER_LOOP);
            //}

            //worker.ReportProgress(OUTER_LOOP * 100 / OUTER_LOOP);
        }