• 0

[VB .NET 2008] Application "not responding mode"


Question

Hello everyone,

I'm having a little headache right now. I have a vn .net 2008 program (.net 4) that does a lot of job in the background. When the user click on a button, the whole form disabled and another form is poped with a progress bar and status information. Then, in the main form, subs and function are ran which send update information to the progress form. Thing is, after a while, the UI thread freeze and the program enter "not responding mode". I've read about doing threads, I tried doing thread but what I want is the main form to stay disabled while the thread is running and the progressform to still be updated.

When using threads, I can't change another thread, it's a protection. So I checked on the web and there is a command to check if the code is ran from the right thread and then change thread if it's not the case and do the job. I've tried these but I get errors.

Then again, for the form to stay disabled, I ran a loop that check if the thread is ended. But then again, it lock up the program.

Thanks

4 answers to this question

Recommended Posts

  • 0

You have to use threading to accomplish your task. The reason the user sees the "not responding" notice is your UI thread is too busy to respond to Window's constant messages to ensure the application is still responding.

Try reading through something like this on threading in .NET.

I haven't read that one as I don't have time at the moment, but if it isn't sufficient it should at least get your feet wet and point you in the right direction.

  • 0

I'd use a background worker to do what you want to do personally. Then just have it bounce back progress to the progress bar, and until the doWorkComplete keep form1.enabled = false.

As for threading, the way I handle cross thread stuff is just invoke what I need done, I make subs that their only purpose is to invoke an update for a label.

ie)


public void UpdateStatusLabel(string msg)
{
try
{
this.Invoke(new MethodInvoker(delegate
{
//Update That label Yo!
lblStatus.Text = msg;
}));
}
catch
{
try
{
//Update That label Yo!
lblStatus.Text = msg;
}
catch (Exception e)
{
//Log what broke
clsMain.Debug.logData("Erroring lblStatus's Caption to: " + msg + ". Error: " + e.Message.ToString(), 1);
}
}
}
[/CODE]

Granted it's C#.. but it works.

  • 0

Ok, it's currently using thread this way:

button click

...

threadImport = New Thread(AddressOf import)

threadImport.SetApartmentState(ApartmentState.MTA)

Me.Enabled = False

threadImport.Start()

threadImport.Join()

Me.Enabled = True

end click

because theadImport isn't part of the same thread as the UI, I can't send the main form (me) the enabled=true command from the thread, it say crossthread operation. Because of that, I use thread.join() to wait for the thread to finish, thus creating a lock.

  • 0

First off, the easy and straight forward way to do this is to simply add the following code in between your hard working method:

Application.DoEvents()

Simply add the Application.DoEvents on the line after you update the progress bar and the method will make windows see that the program is responding.

This is very easy to implement, easy to understand, but also very very limited.

For most applications, you want to do the job (the import) in a separate thread like you have attempted at. There are lots of things you have to remember when working with threads however:

Like you said, threads cannot change UI, because UI elements are only allowed to change through the "UI" thread (the thread that runs when you click a button). To solve this, you have something called delegates which is basicly that your thread tells the UI to run some code next chance it has.

If one thread (like the button click function) has to wait for another thread (your threadImport) you write thread.Join() - this makes the thread lock up and you are back to square one again, UI becomes unresponsive. Unless you have a good reason, stay away from Join().

You have already understood how to run things in their own thread, so here's a link that shows you a bit more about how to update your UI on a separate thread (delegates and invokes and all that fancy stuff). What you need to do is move the Me.Enabled back into the thread using delegates, and remove the threadImport.Join() from your click function.

http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx

There's a very nice and readable example that should help you understand more about invoke and delegate.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Ea and Ubisoft's already have a 3rd party client mode where it removes the store features from the client and only uses 60mb of ram rather than 700.... I use playnite for gog and epic games because the the third party legendary client etc Combined in playnite epic and gog only use 200mb/ram while also showing my entire library from every other platform...
    • Also, this domain thing only works with Pro version of Windows, not the home version
    • More useless bloat to kill your pc by accident
    • Windows 11 gets more customization, a Recall home page, and more in new builds by Taras Buria Microsoft kicks off this Monday with a duo of nearly identical builds for Windows Insiders in the Dev and Beta Channels. Build 26200.5661 (Dev) and 26120.4452 (Beta) are now available for download with two big changes: a new home page for Recall and the recently spotted ability to customize where system indicators appear on the screen. The new Recall home page features more personalized content to help you get back to recent activities. It displays your latest snapshots and a curated view of the top three applications and websites you have spent the most time on in the past 24 hours. Here is what it looks like: In addition, Recall received a new nav bar on the left side of the screen with quick links to Home, Timeline, Feedback, and Settings. The next big addition is the ability to change where system indicators (brightness, volume, and more) appear on the screen. Now, you can set these at the top-left corner or top-center. To adjust this, go to Settings > System > Notifications > Position of the onscreen pop-up. Here are other changes included in today's builds: [Start menu] We are adding a Boolean to the Configure Start Pins policy to allow admins to apply Start menu pins once. This means that a user will receive admin pins on day 0 but can then make any changes to their Start pinned layout and have those safeguarded. These changes can be optionally applied through the existing configuration service provider (CSP). [File Explorer] We are restarting the roll out of AI actions in File Explorer that began rolling out with Build 26120.4151. Some Insiders may have seen the feature disappear. [Settings] In the most recently flights, we have added the country or region selected during device setup under Settings > Time & language > Language & region. Here is what was fixed: [General] Fixed the issue causing the Windows Vista boot sound to play instead of the Windows 11 boot sound. Fixed an issue where the option to reset your PC under Settings > System > Recovery wasn’t working on the previous build. Fixed an underlying issue leading to certain KVM virtual machines unexpectedly failing to boot, showing “UNSUPPORTED_PROCESSOR”. The Dev build has an extra fix: Fixed the issue causing a small number of Insiders to experience repeated bugchecks with KERNEL_SECURITY_CHECK_FAILURE after upgrading to most current Dev Channel builds. Known issues include the following: [General] [IMPORTANT NOTE] When joining the Beta Channel on Windows 11, version 24H2 – you will be offered Build 26120.4250 After installing Build 26120.4250, you will be offered the most recent update available. This 2-hop experience to get onto the latest flight in the Beta Channel is just temporary. After you do a PC reset under Settings > System > Recovery, your build version may incorrectly show as Build 26100 instead of Build 26120. This will not prevent you from getting future Beta Channel updates, which will resolve this issue. Some Windows Insiders may experience a rollback trying to install this update with a 0x80070005 in Windows Update. We’re working on a fix for Windows Insiders impacted. [Start menu] The following are known issues for Windows Insiders with the new Start menu: Using touch to navigate the new Start menu may not work reliably. For example, it currently does not support the swipe-up gesture. Drag and drop capabilities are limited from “All” to “Pinned.” In some cases, duplicate entries may appear in folders on the Start menu. [Xbox Controllers] Some Insiders are experiencing an issue where using their Xbox Controller via Bluetooth is causing their PC to bugcheck. Here is how to resolve the issue. Open Device Manager by searching for it via the search box on your taskbar. Once Device Manager is open, click on “View” and then “Devices by Driver”. Find the driver named “oemXXX.inf (XboxGameControllerDriver.inf)” where the “XXX” will be a specific number on your PC. Right-click on that driver and click “Uninstall”. [Click to Do (Preview)] The following known issues will be fixed in future updates to Windows Insiders: Windows Insiders on AMD or Intel™-powered Copilot+ PCs may experience long wait times on the first attempt to perform intelligent text actions in Click to Do after a new build or model update. [File Explorer] The following are known issues for AI actions in File Explorer: Narrator scan mode may not work properly in the action result canvas window for the Summarize AI action for Microsoft 365 files when reading bulleted lists. As a workaround, you can use Caps + Right key to navigate. [Widgets] Until we complete support for pinning in the new widgets board experience, pinning reverts you back to the previous experience You can find the announcement for the Dev build here and for the Beta build here.
  • Recent Achievements

    • One Month Later
      adnan.hebibovic earned a badge
      One Month Later
    • Week One Done
      adnan.hebibovic earned a badge
      Week One Done
    • Dedicated
      tesla maxwell earned a badge
      Dedicated
    • Dedicated
      Camlann earned a badge
      Dedicated
    • Week One Done
      fredss earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      629
    2. 2
      Michael Scrip
      224
    3. 3
      ATLien_0
      220
    4. 4
      +FloatingFatMan
      145
    5. 5
      Xenon
      135
  • Tell a friend

    Love Neowin? Tell a friend!