Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Problems with background worker - progress bar

C# Problems with background worker - progress bar

Scheduled Pinned Locked Moved C#
csharphelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wheels012
    wrote on last edited by
    #1

    Good morning all. I am coming up with an error: Cross-thread operation not valid. Attempted to access from a thread other than the thread it was created on. My code:

    private void btnSubmit_Click(object sender, EventArgs e)
    {

            if (tbRACFID.Text == string.Empty)
            {
                MessageBox.Show("You must have a RACFID in order to continue.", "RACFID Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                ff.ControlSetFocus(tbRACFID);
                return;
            }
            if (tbUserName.Text == string.Empty)
            {
                MessageBox.Show("You must have a User Name in order to continue.", "User Name Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                ff.ControlSetFocus(tbUserName);
                return;
            }
    
            PwdSecurity p = new PwdSecurity();
            uipc = this.Parent as UIPCMainForm;
            string strContainer = cbEndUserDepart.SelectedValue.ToString() + tbRACFID.Text.ToLower();
            DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
    
            this.backgroundWorker1.RunWorkerAsync();
    
            btnReset.PerformClick();
        }
    

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    PwdSecurity p = new PwdSecurity();
    uipc = this.Parent as UIPCMainForm;
    string strContainer = cbEndUserDepart.SelectedValue.ToString() + tbRACFID.Text.ToLower(); //ERROR Line
    DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));

            BackgroundWorker worker = (BackgroundWorker)sender;
    
            //Obtain Propper Subnet IP Address based on the Router Type from the Routr table, and
            //the DMVPN Subnet Type from the SubntSize table
    
            string SubnetIPAddress = string.Empty;
            DataSet ds = new DataSet();
            ds = d.FillDropDowns(4); //Subnet Size IP
            foreach (DataRow dr in ds.Tables\[0\].Rows)
            {
                if (
                    dr\["ROUTR\_TYPE"\].ToString() == cbRouter.Text &&
                    dr\["LOC"\].ToString() == cbLocation.SelectedValue.ToString())
                {
                    SubnetIPAddress = dr\["SUBNT\_IPADR"\].ToString();
                }
            }
    
            d.importContainer(
            strContainer,
            tbUserName.Text,
            cbRouter.SelectedValue.ToString(),
            (int)arSubNetList\[
    
    L 1 Reply Last reply
    0
    • W Wheels012

      Good morning all. I am coming up with an error: Cross-thread operation not valid. Attempted to access from a thread other than the thread it was created on. My code:

      private void btnSubmit_Click(object sender, EventArgs e)
      {

              if (tbRACFID.Text == string.Empty)
              {
                  MessageBox.Show("You must have a RACFID in order to continue.", "RACFID Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                  ff.ControlSetFocus(tbRACFID);
                  return;
              }
              if (tbUserName.Text == string.Empty)
              {
                  MessageBox.Show("You must have a User Name in order to continue.", "User Name Field Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                  ff.ControlSetFocus(tbUserName);
                  return;
              }
      
              PwdSecurity p = new PwdSecurity();
              uipc = this.Parent as UIPCMainForm;
              string strContainer = cbEndUserDepart.SelectedValue.ToString() + tbRACFID.Text.ToLower();
              DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
      
              this.backgroundWorker1.RunWorkerAsync();
      
              btnReset.PerformClick();
          }
      

      private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
      {
      PwdSecurity p = new PwdSecurity();
      uipc = this.Parent as UIPCMainForm;
      string strContainer = cbEndUserDepart.SelectedValue.ToString() + tbRACFID.Text.ToLower(); //ERROR Line
      DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));

              BackgroundWorker worker = (BackgroundWorker)sender;
      
              //Obtain Propper Subnet IP Address based on the Router Type from the Routr table, and
              //the DMVPN Subnet Type from the SubntSize table
      
              string SubnetIPAddress = string.Empty;
              DataSet ds = new DataSet();
              ds = d.FillDropDowns(4); //Subnet Size IP
              foreach (DataRow dr in ds.Tables\[0\].Rows)
              {
                  if (
                      dr\["ROUTR\_TYPE"\].ToString() == cbRouter.Text &&
                      dr\["LOC"\].ToString() == cbLocation.SelectedValue.ToString())
                  {
                      SubnetIPAddress = dr\["SUBNT\_IPADR"\].ToString();
                  }
              }
      
              d.importContainer(
              strContainer,
              tbUserName.Text,
              cbRouter.SelectedValue.ToString(),
              (int)arSubNetList\[
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, Here[^] is the full description of your problem. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      D W 2 Replies Last reply
      0
      • L Luc Pattyn

        Hi, Here[^] is the full description of your problem. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        D Offline
        D Offline
        Druuler
        wrote on last edited by
        #3

        but isnt the purpose of backgroundworker that u dont need to explicitly invoke the controls? if i call worker.ReportProgress i dont need to invoke the controls and they are updated without cross threading exceptions! i might have missed but idont see you calling worker.ReportProgress from your worker_DoWork method?

        modified on Tuesday, August 4, 2009 11:37 AM

        L 1 Reply Last reply
        0
        • D Druuler

          but isnt the purpose of backgroundworker that u dont need to explicitly invoke the controls? if i call worker.ReportProgress i dont need to invoke the controls and they are updated without cross threading exceptions! i might have missed but idont see you calling worker.ReportProgress from your worker_DoWork method?

          modified on Tuesday, August 4, 2009 11:37 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Two of the BGW events are handled on the main thread; and obviously DoWork is not, otherwise nothing would be going on in the background. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


          1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, Here[^] is the full description of your problem. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


            W Offline
            W Offline
            Wheels012
            wrote on last edited by
            #5

            Thank you Luc.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups