Click here to Skip to main content
15,884,810 members
Home / Discussions / C#
   

C#

 
GeneralRe: Code Sends Me To A New Page Before Completion Pin
Richard MacCutchan11-Jul-11 4:55
mveRichard MacCutchan11-Jul-11 4:55 
AnswerRe: Code Sends Me To A New Page Before Completion Pin
BobJanova10-Jul-11 22:17
BobJanova10-Jul-11 22:17 
GeneralRe: Code Sends Me To A New Page Before Completion Pin
PDTUM11-Jul-11 4:11
PDTUM11-Jul-11 4:11 
QuestionControlMessage Pin
Snow White_10-Jul-11 2:13
Snow White_10-Jul-11 2:13 
AnswerRe: ControlMessage Pin
Dave Kreskowiak10-Jul-11 3:44
mveDave Kreskowiak10-Jul-11 3:44 
AnswerRe: ControlMessage Pin
thatraja10-Jul-11 9:27
professionalthatraja10-Jul-11 9:27 
Questionunblock some item in form Pin
abdellah ab9-Jul-11 8:30
abdellah ab9-Jul-11 8:30 
AnswerRe: unblock some item in form Pin
Heath Stewart9-Jul-11 8:55
protectorHeath Stewart9-Jul-11 8:55 
It would seem you're blocking the UI thread - you're making the UI thread do so much work it can't keep up with all the other requests like to repaint. I assume you're executing this code in response to some control event or initialization code?

While I'm sure this is just an example, assuming there's other work you should do that work in a worker thread and invoke the property setting on the UI thread since many times executing code on a control in a different thread than in which it was created can cause issues.

First you'll need to define a method to set your image property.

private void SetImageLocation(string uri)
{
  if (pictureBox1.InvokeRequired)
  {
    Action<string> setImageLocation = SetImageLocation;
    pictureBox1.Invoke(setImageLocation, new object[] { uri });
  }
  else
  {
    pictureBox1.ImageLocation = uri;
  }
}


To create a worker thread, consider using the ThreadPool like so:

private void DoWork()
{
  for (int i = 0; i < 20000; ++i)
  {
    if (i == 5000)
    {
      SetImageLocation("x.gif");
    }
  }
}

// Assumes you're executing work in response to a Button.Click event.
private void button1_Click(object sender, EventArgs e)
{
  ThreadPool.QueueUserWorkItem(DoWork);
}

This posting is provided "AS IS" with no warranties, and confers no rights.

Program Manager II
Visual Studio Professional Deployment Experience
Microsoft

[My Articles] [My Blog]

AnswerRe: unblock some item in form Pin
DaveAuld9-Jul-11 9:05
professionalDaveAuld9-Jul-11 9:05 
AnswerRe: unblock some item in form Pin
Dr.Walt Fair, PE9-Jul-11 10:38
professionalDr.Walt Fair, PE9-Jul-11 10:38 
GeneralRe: unblock some item in form Pin
BobJanova10-Jul-11 22:19
BobJanova10-Jul-11 22:19 
GeneralRe: unblock some item in form Pin
DaveAuld11-Jul-11 2:47
professionalDaveAuld11-Jul-11 2:47 
GeneralRe: unblock some item in form Pin
BobJanova11-Jul-11 3:37
BobJanova11-Jul-11 3:37 
QuestionCreate Dial Up Connection Pin
jojoba20119-Jul-11 6:06
jojoba20119-Jul-11 6:06 
AnswerRe: Create Dial Up Connection Pin
Heath Stewart10-Jul-11 16:08
protectorHeath Stewart10-Jul-11 16:08 
QuestionBreak code execution from base class in inherited form Pin
RobScripta9-Jul-11 4:30
professionalRobScripta9-Jul-11 4:30 
AnswerRe: Break code execution from base class in inherited form Pin
Heath Stewart9-Jul-11 9:16
protectorHeath Stewart9-Jul-11 9:16 
GeneralRe: Break code execution from base class in inherited form Pin
RobScripta9-Jul-11 9:29
professionalRobScripta9-Jul-11 9:29 
GeneralRe: Break code execution from base class in inherited form Pin
Dave Kreskowiak9-Jul-11 10:12
mveDave Kreskowiak9-Jul-11 10:12 
GeneralRe: Break code execution from base class in inherited form Pin
Heath Stewart10-Jul-11 16:16
protectorHeath Stewart10-Jul-11 16:16 
Questiondouble buffering Pin
shvanisingh9-Jul-11 3:54
shvanisingh9-Jul-11 3:54 
AnswerRe: double buffering Pin
fjdiewornncalwe9-Jul-11 4:57
professionalfjdiewornncalwe9-Jul-11 4:57 
AnswerRe: double buffering Pin
OriginalGriff9-Jul-11 5:24
mveOriginalGriff9-Jul-11 5:24 
AnswerRe: double buffering Pin
Pete O'Hanlon9-Jul-11 6:31
mvePete O'Hanlon9-Jul-11 6:31 
Questionclass with dynamic property Pin
mehrdadc488-Jul-11 21:14
mehrdadc488-Jul-11 21:14 

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.