Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More VFP nostalgia : wait nowait
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Vista
Network:
Windows XP
Database:
Jet/Access Engine
Application:
Desktop
Miscellaneous
Thread ID:
01525944
Message ID:
01525959
Views:
68
It's pretty straightforward.
(a) Create a BackgroundWorker Instance.
(b) Wire it up so that when RunWorkerAsync is called it runs whatever code should be executed in the backgound in bgw_DoWork.
(c) Set the WorkerReportsProgress true
(d) Wire up the bgw_ProgressChanged method so that it is called when .ReportProgress is raised in the bgw_DoWork.
(e) Update the progress bar (or do something else) in the bgw_ProgressChanged callback.

If you want to perform some other action when the worker completes then wire up the RunWorkerCompleted event as well.

The example below is self-contained and debugging that with breakpoints should make it easy to understand what's going on.
(Don't forget there's a pretty good C# => VB.NET converter at http://www.developerfusion.com/tools/convert/csharp-to-vb/ )



>Thanks. I'll try to figure it out :)
>
>
>>FWIW your simplest approach to multi-threading would be to use the BackgroundWorker class. Simple example (assuming the form has a button1 button and a progressBar1 ProgressBar:
    public partial class Form1 : Form
>>    {
>>        public Form1()
>>        {
>>            InitializeComponent();
>>         }
>>
>>        private void button1_Click(object sender, EventArgs e)
>>        {
>>            BackgroundWorker bgw = new BackgroundWorker();
>>            bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
>>            bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
>>            bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
>>            bgw.WorkerReportsProgress = true;
>>            bgw.RunWorkerAsync();
>>         }
>>
>>        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
>>        {
>>            progressBar1.Value = 0;
>>        }
>>
>>        void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
>>        {
>>            progressBar1.Value = e.ProgressPercentage;
>>        }
>>
>>        void bgw_DoWork(object sender, DoWorkEventArgs e)
>>        {
>>            BackgroundWorker bgw = sender as BackgroundWorker;
>>            //Simulate long task.....
>>            for (int i = 0; i < 10; i++)
>>            {
>>                System.Threading.Thread.Sleep(i * 250);
>>                bgw.ReportProgress(i * 10);
>>            }
>> 
>>        }
>>    }
>>
>>
>>>Let me reassure you, there is nothing "anal" about my attachment to the WAIT WINDOW NOWAIT behaviour in vfp, other than that it was so damn easy to use :)
>>>
>>>I'm looking for a way to display some "monitoring", keeping my users from becoming impatient, during a process that takes more than say a few seconds (yes, my users are high-strung :) )
>>>
>>>You figure multi-threading (something I kept away from all those years) is worth exploring in this context?
>>>
>>>Thanks for all your help (even when you think you're not, (and that's the only time you can be caught for being wrong) (I guess in C# you don't mind all those parentheses) you are helping dear :) ).
>>>
>>>Kind regards,
>>>
>>>Marc
>>>
>>>
>>>
>>>
>>>>I don't have anything :-{
>>>>
>>>>I'm also a bit rusty on the actual VFP implementation but I assume you would most likely want WAIT WINDOW NOWAIT behaviour.
>>>>IAC it wouldn't be trivial. AFAICS you'd need a form subclass using .Show() or ShowDialog() depending on the NOWAIT flag, a timer to implement TIMEOUT and also have to monitor keyboard and mouse activity to determine when to hide/close the window.
>>>>
>>>>My gut feeling is that this is a VFP specific piece of behaviour which wouldn't normally be seen in a Winforms app anyway and, unless there is a very compelling reason, it would be better to rething the interface.
>>>>
>>>>Won't say HTH because I'm sure it doesn't :-{
>>>>
>>>>>Winforms. ... and I guess I can read C#, so if you have something, do not bother to translate it... (or to be more realistic, if there is something I don't understand, I'll ask. :) )
>>>>>
>>>>>
>>>>>>Is this WinForms, WPF or ASP.NET ?
>>>>>>
>>>>>>>Anybody coded a simple replacement of the "wait nowait" statement in vb.net.
>>>>>>>
>>>>>>>Thanks and kind regards,
>>>>>>>
>>>>>>>Marc
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform