Not multitasking by default ? (VB .NET) 
Author Message
 Not multitasking by default ? (VB .NET)

Hello people,

I a new to this, so this might be a stupid question, but here goes:

In the following code (part of a subroutine), I am generating license keys
and writing them in a textbox (LicenseKeys). It all works fine and all keys
are generated correctly. The progressbar (ProgressBar1) and a label
(lblProcessing) indicating which number is generated all work fine.

However, if I do something else on my PC while this routine runs (doesn't
matter what, launching Explorer, launching task manager,...), my program
locks up. I don't understand why. Do I have to tell VB somewhere this is
supposed to be a multitasking program or what ?

Regards,

Benoit.

For i = StartSerialNumber To EndSerialNumber

LicenseKey.SerialNumber = i

LicenseToUse = GenerateLicenseKey(LicenseKey.SerialNumber)

LicenseKeys.Text = LicenseKeys.Text & LicenseToUse & vbCrLf

ProgressBar1.Value = i

lblProcessing.Text = "Generating key " & i

lblProcessing.Refresh()

Next



Wed, 16 Nov 2005 01:13:52 GMT  
 Not multitasking by default ? (VB .NET)
Try sticking:

Windows.Forms.Application.DoEvents()

in the loop.

steve


Quote:
> Hello people,

> I a new to this, so this might be a stupid question, but here goes:

> In the following code (part of a subroutine), I am generating license keys
> and writing them in a textbox (LicenseKeys). It all works fine and all
keys
> are generated correctly. The progressbar (ProgressBar1) and a label
> (lblProcessing) indicating which number is generated all work fine.

> However, if I do something else on my PC while this routine runs (doesn't
> matter what, launching Explorer, launching task manager,...), my program
> locks up. I don't understand why. Do I have to tell VB somewhere this is
> supposed to be a multitasking program or what ?

> Regards,

> Benoit.

> For i = StartSerialNumber To EndSerialNumber

> LicenseKey.SerialNumber = i

> LicenseToUse = GenerateLicenseKey(LicenseKey.SerialNumber)

> LicenseKeys.Text = LicenseKeys.Text & LicenseToUse & vbCrLf

> ProgressBar1.Value = i

> lblProcessing.Text = "Generating key " & i

> lblProcessing.Refresh()

> Next



Wed, 16 Nov 2005 01:27:57 GMT  
 Not multitasking by default ? (VB .NET)

Hello Steve,

Right on the spot ! Thanks a lot.

I lookup this up, but I can only find a little bit of information. Could you
explain a little bit what this does exactly ?

Again, many thanks,

Benoit.


Quote:
> Try sticking:

> Windows.Forms.Application.DoEvents()

> in the loop.

> steve



> > Hello people,

> > I a new to this, so this might be a stupid question, but here goes:

> > In the following code (part of a subroutine), I am generating license
keys
> > and writing them in a textbox (LicenseKeys). It all works fine and all
> keys
> > are generated correctly. The progressbar (ProgressBar1) and a label
> > (lblProcessing) indicating which number is generated all work fine.

> > However, if I do something else on my PC while this routine runs
(doesn't
> > matter what, launching Explorer, launching task manager,...), my program
> > locks up. I don't understand why. Do I have to tell VB somewhere this is
> > supposed to be a multitasking program or what ?

> > Regards,

> > Benoit.

> > For i = StartSerialNumber To EndSerialNumber

> > LicenseKey.SerialNumber = i

> > LicenseToUse = GenerateLicenseKey(LicenseKey.SerialNumber)

> > LicenseKeys.Text = LicenseKeys.Text & LicenseToUse & vbCrLf

> > ProgressBar1.Value = i

> > lblProcessing.Text = "Generating key " & i

> > lblProcessing.Refresh()

> > Next



Wed, 16 Nov 2005 02:22:39 GMT  
 Not multitasking by default ? (VB .NET)
I'm not sure the exact mechanism of what it does, except it allows a pause
in VB's operations to let other threads have a chance to be serviced.

This explanation is not very helpful:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindows...

steve


Quote:

> Hello Steve,

> Right on the spot ! Thanks a lot.

> I lookup this up, but I can only find a little bit of information. Could
you
> explain a little bit what this does exactly ?

> Again, many thanks,

> Benoit.



> > Try sticking:

> > Windows.Forms.Application.DoEvents()

> > in the loop.

> > steve



> > > Hello people,

> > > I a new to this, so this might be a stupid question, but here goes:

> > > In the following code (part of a subroutine), I am generating license
> keys
> > > and writing them in a textbox (LicenseKeys). It all works fine and all
> > keys
> > > are generated correctly. The progressbar (ProgressBar1) and a label
> > > (lblProcessing) indicating which number is generated all work fine.

> > > However, if I do something else on my PC while this routine runs
> (doesn't
> > > matter what, launching Explorer, launching task manager,...), my
program
> > > locks up. I don't understand why. Do I have to tell VB somewhere this
is
> > > supposed to be a multitasking program or what ?

> > > Regards,

> > > Benoit.

> > > For i = StartSerialNumber To EndSerialNumber

> > > LicenseKey.SerialNumber = i

> > > LicenseToUse = GenerateLicenseKey(LicenseKey.SerialNumber)

> > > LicenseKeys.Text = LicenseKeys.Text & LicenseToUse & vbCrLf

> > > ProgressBar1.Value = i

> > > lblProcessing.Text = "Generating key " & i

> > > lblProcessing.Refresh()

> > > Next



Wed, 16 Nov 2005 03:27:14 GMT  
 Not multitasking by default ? (VB .NET)

Quote:

> I'm not sure the exact mechanism of what it does, except it allows a pause
> in VB's operations to let other threads have a chance to be serviced.

> This explanation is not very helpful:

> http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindows...

> steve



>>Hello Steve,

>>Right on the spot ! Thanks a lot.

>>I lookup this up, but I can only find a little bit of information. Could

> you

>>explain a little bit what this does exactly ?

>>Again, many thanks,

>>Benoit.

Think of it as "Co-Operative Multi-Tasking"...
Instead of "Pre-Emptive Multi-Tasking".


Wed, 16 Nov 2005 03:37:01 GMT  
 Not multitasking by default ? (VB .NET)

says...

Quote:
> However, if I do something else on my PC while this routine runs (doesn't
> matter what, launching Explorer, launching task manager,...), my program
> locks up.

What do you mean by "locks up"?  Do you mean the app is frozen and you
need to use TaskManager to kill it?  Or do you simply mean the screen is
no longer refreshed properly.

If it's really locked up, there's a bug you need to find and fix.  If it
appears to be not responding, it's probably because the thread is busy
processing your code and doesn't have time to process windows paint
messages.

You could consider starting a new thread to do the intensive code and
use the Control.Invoke method to update the form.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele



Wed, 16 Nov 2005 03:54:44 GMT  
 Not multitasking by default ? (VB .NET)

Thanks all for the support guys.

I don't understand fully yet how this works (and yes, my app is frozen and I
need the TaskManager to kill it), but Windows.Forms.Application.DoEvents()
statement takes nicely care of it !

Regards,

Benoit.



Quote:

> says...
> > However, if I do something else on my PC while this routine runs
(doesn't
> > matter what, launching Explorer, launching task manager,...), my program
> > locks up.

> What do you mean by "locks up"?  Do you mean the app is frozen and you
> need to use TaskManager to kill it?  Or do you simply mean the screen is
> no longer refreshed properly.

> If it's really locked up, there's a bug you need to find and fix.  If it
> appears to be not responding, it's probably because the thread is busy
> processing your code and doesn't have time to process windows paint
> messages.

> You could consider starting a new thread to do the intensive code and
> use the Control.Invoke method to update the form.

> --
> Patrick Steele
> Microsoft .NET MVP
> http://weblogs.asp.net/psteele



Wed, 16 Nov 2005 05:02:24 GMT  
 Not multitasking by default ? (VB .NET)


Quote:
> but Windows.Forms.Application.DoEvents()
> statement takes nicely care of it !

Ok, then it really isn't "locked up", it's so busy doing stuff that when
windows sends it a Paint message (basically saying "ok, you need to
repaint yourself"), the paint message isn't being processed because your
code is busy doing it's own logic.

Likewise, when Task Manager sees that an app isn't processing messages
being sent to it, it lists its status as "Not Responding".  That's not
the same as "locked up" (although many people think that).

The DoEvents basically lets your app code pause a little and gives a
chance for the messages that are backing up (such as Paint messages) to
be processed.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele



Wed, 16 Nov 2005 21:25:04 GMT  
 Not multitasking by default ? (VB .NET)
Hi Benoit,

My considered advice is to look at your problem in more detail. What you've
done is called "debugging by superstition", and it's a very dangerous way to
program. If you don't understand the problem, it's not safe to add some
"magic" that appears to solve the problem. The magic might just be hiding
the problem, so that it only appears again when you're demonstrating your
program to your boss or when your most important customer uses it.

Patrick is absolutely correct. If there's a real bug in your code, the
DoEvents might *temporarily* be hiding the bug. If your thread is busy
processing stuff, you may need to split your app into a worker thread and a
UI thread. Or maybe you've already done that, and now you're trying to
update your UI directly from the worker thread. This is a definite no-no and
can cause mysterious intermittent bugs (use Control.Invoke instead).

HTH,

Mark
--
Author of "Comprehensive VB .NET Debugging"
http://www.apress.com/book/bookDisplay.html?bID=128


Thanks all for the support guys.

I don't understand fully yet how this works (and yes, my app is frozen and I
need the TaskManager to kill it), but Windows.Forms.Application.DoEvents()
statement takes nicely care of it !

Regards,

Benoit.



Quote:

> says...
> > However, if I do something else on my PC while this routine runs
(doesn't
> > matter what, launching Explorer, launching task manager,...), my program
> > locks up.

> What do you mean by "locks up"?  Do you mean the app is frozen and you
> need to use TaskManager to kill it?  Or do you simply mean the screen is
> no longer refreshed properly.

> If it's really locked up, there's a bug you need to find and fix.  If it
> appears to be not responding, it's probably because the thread is busy
> processing your code and doesn't have time to process windows paint
> messages.

> You could consider starting a new thread to do the intensive code and
> use the Control.Invoke method to update the form.

> --
> Patrick Steele
> Microsoft .NET MVP
> http://weblogs.asp.net/psteele



Wed, 16 Nov 2005 21:23:36 GMT  
 Not multitasking by default ? (VB .NET)

Hello Mark (& others),

Well thanks for the good advise !

Thing is that I really don't see where the bug could be. The code I showed
earlier is all there is and basically the function that generates the
license key does nothing more than a few basic calculations.

Describing the problems I had, is there any specific suggestion you could
make that could point me in the right direction ?

What do you think of the last message of Patrick Steele ? It makes sense and
if this is indeed the case, it also makes sense that the DoEvents works like
magic in this case...

Many thanks again,

Benoit.


Quote:
> Hi Benoit,

> My considered advice is to look at your problem in more detail. What
you've
> done is called "debugging by superstition", and it's a very dangerous way
to
> program. If you don't understand the problem, it's not safe to add some
> "magic" that appears to solve the problem. The magic might just be hiding
> the problem, so that it only appears again when you're demonstrating your
> program to your boss or when your most important customer uses it.

> Patrick is absolutely correct. If there's a real bug in your code, the
> DoEvents might *temporarily* be hiding the bug. If your thread is busy
> processing stuff, you may need to split your app into a worker thread and
a
> UI thread. Or maybe you've already done that, and now you're trying to
> update your UI directly from the worker thread. This is a definite no-no
and
> can cause mysterious intermittent bugs (use Control.Invoke instead).

> HTH,

> Mark
> --
> Author of "Comprehensive VB .NET Debugging"
> http://www.apress.com/book/bookDisplay.html?bID=128



> Thanks all for the support guys.

> I don't understand fully yet how this works (and yes, my app is frozen and
I
> need the TaskManager to kill it), but Windows.Forms.Application.DoEvents()
> statement takes nicely care of it !

> Regards,

> Benoit.




> > says...
> > > However, if I do something else on my PC while this routine runs
> (doesn't
> > > matter what, launching Explorer, launching task manager,...), my
program
> > > locks up.

> > What do you mean by "locks up"?  Do you mean the app is frozen and you
> > need to use TaskManager to kill it?  Or do you simply mean the screen is
> > no longer refreshed properly.

> > If it's really locked up, there's a bug you need to find and fix.  If it
> > appears to be not responding, it's probably because the thread is busy
> > processing your code and doesn't have time to process windows paint
> > messages.

> > You could consider starting a new thread to do the intensive code and
> > use the Control.Invoke method to update the form.

> > --
> > Patrick Steele
> > Microsoft .NET MVP
> > http://weblogs.asp.net/psteele



Thu, 17 Nov 2005 02:41:01 GMT  
 Not multitasking by default ? (VB .NET)

Hello Patrick,

This makes a lot of sense to me and could explain what happens. Please see
also my remarks to the last reply of Mark Pearce.

Like I said before, I am new to this and I'm impressed with the quality and
dedication of the replies I see here...

Thanks, people.

Regards,

Benoit.



Quote:


> > but Windows.Forms.Application.DoEvents()
> > statement takes nicely care of it !

> Ok, then it really isn't "locked up", it's so busy doing stuff that when
> windows sends it a Paint message (basically saying "ok, you need to
> repaint yourself"), the paint message isn't being processed because your
> code is busy doing it's own logic.

> Likewise, when Task Manager sees that an app isn't processing messages
> being sent to it, it lists its status as "Not Responding".  That's not
> the same as "locked up" (although many people think that).

> The DoEvents basically lets your app code pause a little and gives a
> chance for the messages that are backing up (such as Paint messages) to
> be processed.

> --
> Patrick Steele
> Microsoft .NET MVP
> http://weblogs.asp.net/psteele



Thu, 17 Nov 2005 02:43:16 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. I do not like the Default setting for VisualStudio.NET

2. *FREE DEMO-NO DREADED WINDOWS HOURGLASS(MULTITASKING SQL*NET)

3. My Vb.Net Apps will not run on other machine's with .Net Framework installed

4. VB.NET app does not run on OS having .NET redistributable files installed

5. Memory not released with vb.net and cr.net

6. I can not INSERT into Access95 using ADO.net and VB.NET

7. SetDataSource not working with Crystal Reports .NET in VB.NET

8. Default is not Default ??

9. Printer, default or not default ?

10. When you tab through maskedit fields the defaultbutton changes from default to not default

11. Non-default parameter not allowed after default parameter

12. Non-default parameter not allowed after default parameter

 

 
Powered by phpBB® Forum Software