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. A problem in multithreading

A problem in multithreading

Scheduled Pinned Locked Moved C#
helpdatabaseperformancequestion
2 Posts 2 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.
  • N Offline
    N Offline
    Nothend
    wrote on last edited by
    #1

    Hello,all: I am using ArcEngine(a software managing spatial data) to upload data(shapefile etc.) to database.Because the process of uploading data is time-consuming,when I click the ProgressBar window or minimize the parent window and then maximize the parent window,the parent window and the ProgressBar window is white using single thread. So,I use multithread to work out this prolem,and it does.But,the speed of uploading data to database slows down greatly . The work uploading data is no more than 10 minutes in single thread,but 40 minutes in multithread!! Who can help me?I appreciate your help!

    private delegate bool UpdateHandle(int nValue,string text);
    private UpdateHandle myUpdate = null;

    myProcessBar is a Window has two controls,a ProgressBar named Bar and a Label named LabelInfo.It has a public method

    BeeUpdate(int value, string text)

    public bool BeeUpdate(int value, string text)
    {
    LabelInfo.Text = text;
    LabelInfo.Refresh();
    if (value > 0)
    {
    if (Bar.Value + value < Bar.Maximum)
    {
    Bar.Value += value;
    Bar.Refresh();
    return true;
    }
    else
    {
    Bar.Value = Bar.Maximum;
    Bar.Refresh();

               this.Close();
               return false;
          }
     }
     return false;
    

    }

    the delegate entry point:

    private void ShowProcessBar()
    {
    myProcessBar = new ProgressBee("Uploading", 100 * ClassCount);

     myUpdate = new UpdateHandle(myProcessBar.BeeUpdate);
    
     myProcessBar.ShowDialog();
    
     myProcessBar = null;
    

    }

    the method called by MainWindow

    //caller is the main window
    public bool CopyTo(parm1, parm2,Form caller)
    {
    MethodInvoker mi = new MethodInvoker(ShowProcessBar);

     mi.BeginInvoke(null, null);
    
     caller.BeginInvoke(mi);
    
     Thread.Sleep(2000);
            
     Thread copyProcess = new Thread(delegate()
     {
          for (int i = 0; i &lt; FeatureClassCount; i++)
          {
               Thread.Sleep(30);
    
               if (condition)
               {
                    //the Interface of ArcEngine  upload data
               }
               else
               {
                    //another Interface of ArcEngine upload data
    
               }
    
               caller.Invoke(this.myUpdate, new object\[\] { 100, "……" });
    
    C 1 Reply Last reply
    0
    • N Nothend

      Hello,all: I am using ArcEngine(a software managing spatial data) to upload data(shapefile etc.) to database.Because the process of uploading data is time-consuming,when I click the ProgressBar window or minimize the parent window and then maximize the parent window,the parent window and the ProgressBar window is white using single thread. So,I use multithread to work out this prolem,and it does.But,the speed of uploading data to database slows down greatly . The work uploading data is no more than 10 minutes in single thread,but 40 minutes in multithread!! Who can help me?I appreciate your help!

      private delegate bool UpdateHandle(int nValue,string text);
      private UpdateHandle myUpdate = null;

      myProcessBar is a Window has two controls,a ProgressBar named Bar and a Label named LabelInfo.It has a public method

      BeeUpdate(int value, string text)

      public bool BeeUpdate(int value, string text)
      {
      LabelInfo.Text = text;
      LabelInfo.Refresh();
      if (value > 0)
      {
      if (Bar.Value + value < Bar.Maximum)
      {
      Bar.Value += value;
      Bar.Refresh();
      return true;
      }
      else
      {
      Bar.Value = Bar.Maximum;
      Bar.Refresh();

                 this.Close();
                 return false;
            }
       }
       return false;
      

      }

      the delegate entry point:

      private void ShowProcessBar()
      {
      myProcessBar = new ProgressBee("Uploading", 100 * ClassCount);

       myUpdate = new UpdateHandle(myProcessBar.BeeUpdate);
      
       myProcessBar.ShowDialog();
      
       myProcessBar = null;
      

      }

      the method called by MainWindow

      //caller is the main window
      public bool CopyTo(parm1, parm2,Form caller)
      {
      MethodInvoker mi = new MethodInvoker(ShowProcessBar);

       mi.BeginInvoke(null, null);
      
       caller.BeginInvoke(mi);
      
       Thread.Sleep(2000);
              
       Thread copyProcess = new Thread(delegate()
       {
            for (int i = 0; i &lt; FeatureClassCount; i++)
            {
                 Thread.Sleep(30);
      
                 if (condition)
                 {
                      //the Interface of ArcEngine  upload data
                 }
                 else
                 {
                      //another Interface of ArcEngine upload data
      
                 }
      
                 caller.Invoke(this.myUpdate, new object\[\] { 100, "……" });
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Threads don't speed things up. They slow them down, by causing your UI thread to also take process time. Having said that, what is your UI doing to use up that much time ?

      Nothend wrote:

      Thread.Sleep(30);

      Why force a sleep in a process that is already slow ?

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      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