Click here to Skip to main content
15,900,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Control Speaker Volume Pin
DaveyM6914-Feb-11 11:45
professionalDaveyM6914-Feb-11 11:45 
GeneralRe: Control Speaker Volume Pin
Kevin Marois14-Feb-11 11:49
professionalKevin Marois14-Feb-11 11:49 
GeneralRe: Control Speaker Volume Pin
DaveyM6914-Feb-11 11:58
professionalDaveyM6914-Feb-11 11:58 
GeneralRe: Control Speaker Volume Pin
DaveyM6914-Feb-11 15:08
professionalDaveyM6914-Feb-11 15:08 
GeneralRe: Control Speaker Volume Pin
Kevin Marois15-Feb-11 5:48
professionalKevin Marois15-Feb-11 5:48 
GeneralRe: Control Speaker Volume Pin
DaveyM6914-Feb-11 11:04
professionalDaveyM6914-Feb-11 11:04 
GeneralRe: Control Speaker Volume Pin
Kevin Marois14-Feb-11 11:08
professionalKevin Marois14-Feb-11 11:08 
QuestionReport Progress from a class with a backgroundWorker Pin
MacRaider414-Feb-11 7:34
MacRaider414-Feb-11 7:34 
Ok so I seem to have my backgroundWorkers worked out. However I can't figure out how to report progress back to the original form. I'll try to pice together the code to have this make sense. FYI I don't have anything in the progressUpdated even yet.

// This is the main form (obviously)
namespace MailTest
{
    public partial class Form1 : Form
    {
        List<BGW> BGWs = new List<BGW>();
        public Form1()
        {
            InitializeComponent();

            for (int i = 0; i < 3; i++)
            {
                BGWs.Add(new BGW());
                BGWs[i].ProgressChanged += BGW_ProgressChanged;
                BGWs[i].RunWorkerCompleted += BGW_WorkerCompleted;
            }

            
            btnGetMessageInfo.Enabled = false;
            //btnCancelConnection.Enabled = false;
        }
        void BGW_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            BGW bgw = (BGW)sender;
        }
        void BGW_WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            BGW bgw = (BGW)sender;
        }
        class BGW : BackgroundWorker
        {
            public BGW()
            {
                this.WorkerReportsProgress = true;
                this.WorkerSupportsCancellation = true;
            }
            protected override void OnDoWork(DoWorkEventArgs e)
            {
                base.OnDoWork(e);
                WriteMail.WriteAndParseMail();
            }
        }

// Further down
        private void btnGetMessageInfo_Click(object sender, EventArgs e)
        {
            processNumberOfWorkers.howMayWorkers();
            MessageBox.Show("There are " + GlobalVars.intHowManyWorkers + " workers needed!");
            btnGetMessageInfo.Enabled = false;
            backgroundWorker2.RunWorkerAsync();
            //backgroundWorker1.RunWorkerAsync();
            BGWs[0].RunWorkerAsync();
        }

// The class being called from the worker
class WriteMail
    {
        public static void WriteAndParseMail()
        {
            int intEmail;
            bool bolSrvMsg;
            //Start of Test Connection
            // create a TCP Client for a TCP Connection
            string txtLogString = null;

            TcpClient tcpClient = new TcpClient();

// further down where the report progress is
                if (percentComplete <= highestPercentageReached)
                {
                    if (percentComplete == 0)
                    {
                        percentComplete = 1;
                    }
                    highestPercentageReached = percentComplete + 1;
                    string strCounter = currentMail + " of " + intEmail;
                    //BGWs[0].ReportProgress(percentComplete, strCounter);
                    // Does not exist in current context
                }


I know I'm probably missing something obvious but still new to backgroundWorkers in C# and not seeing many examples for doing this from a class. When I do it from the main form with a different backgroundWorker it works fine, but when I changed it to this "type" it didn't like the function on the same class so I had to create a new one (which I wanted to do anyways).

Thanks in advance!!!!
AnswerRe: Report Progress from a class with a backgroundWorker Pin
Luc Pattyn14-Feb-11 7:42
sitebuilderLuc Pattyn14-Feb-11 7:42 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
MacRaider414-Feb-11 7:57
MacRaider414-Feb-11 7:57 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
Luc Pattyn14-Feb-11 8:13
sitebuilderLuc Pattyn14-Feb-11 8:13 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
MacRaider414-Feb-11 8:21
MacRaider414-Feb-11 8:21 
AnswerRe: Report Progress from a class with a backgroundWorker Pin
Ian Shlasko14-Feb-11 8:11
Ian Shlasko14-Feb-11 8:11 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
MacRaider414-Feb-11 8:28
MacRaider414-Feb-11 8:28 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
Ian Shlasko14-Feb-11 9:31
Ian Shlasko14-Feb-11 9:31 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
MacRaider414-Feb-11 9:46
MacRaider414-Feb-11 9:46 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
Ian Shlasko14-Feb-11 12:11
Ian Shlasko14-Feb-11 12:11 
GeneralRe: Report Progress from a class with a backgroundWorker Pin
DaveyM6914-Feb-11 11:24
professionalDaveyM6914-Feb-11 11:24 
QuestionSet a picture transparently in the foreground Pin
Mschauder14-Feb-11 2:21
Mschauder14-Feb-11 2:21 
AnswerRe: Set a picture transparently in the foreground Pin
musefan14-Feb-11 3:03
musefan14-Feb-11 3:03 
GeneralRe: Set a picture transparently in the foreground Pin
Mschauder14-Feb-11 3:15
Mschauder14-Feb-11 3:15 
GeneralRe: Set a picture transparently in the foreground Pin
musefan14-Feb-11 3:42
musefan14-Feb-11 3:42 
GeneralRe: Set a picture transparently in the foreground Pin
Mschauder14-Feb-11 22:08
Mschauder14-Feb-11 22:08 
Questiondirectory path Pin
arkiboys13-Feb-11 22:12
arkiboys13-Feb-11 22:12 
AnswerRe: directory path Pin
Pete O'Hanlon13-Feb-11 22:17
mvePete O'Hanlon13-Feb-11 22: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.