For an application I'm creating I want to create a 'fake' progress
bar.
By fake I mean a progress bar that looks like it's doing something but
actually isn't.
I know philosophically this isn't sound. But my little app is a 'fake'
app and is designed to look like another - hence this seeming crazy
situation of needing to fake a progess bar.
PROBLEM.
I can not figure out how to delay the execution of my code to pause
between updates of the progress bar value, I had thought i could do
something like this.
progressbar1.value = 10;
wait for 20 seconds....
progressbar1.value=50;
wait for 10 seconds....
progressbar1.value=90;
etc... The problem I have is that the only method i've managed to find
of pausing code execution is the thread.sleep method. However this
causes the form not to be displayed, from what i've gathered this is
because the part of the code that actually paints the form is
disrupted by the call to make the thread sleep.
My Attempted Solution.
I tried to create a new thread and put the code that deals with the
progress bar in that thread. This created an error about cross thread
referencing. I then disabled cross thread referencing using
Control.CheckForIllegalCrossThreadCalls = false; but it's still not
working.
Any ideas how to fix this.
Here is what I have so far.
=====================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Stealth
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
}
private void myStartingMethod()
{
//change value to 20.
progressBar1.Value = 20;
//pause
System.Threading.Thread.Sleep(5000);
//change value to 90.
progressBar1.Value = 90;
}
private void Form3_Load(object sender, EventArgs e)
{
InitializeComponent();
System.Threading.Thread myThread;
myThread = new System.Threading.Thread(new
System.Threading.ThreadStart(myStartingMethod));
myThread.Start();
}
}
}
=================
TIA.