• 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

    • Gundams to arrive in Call of Duty: Mobile with new mech mode and unique third-person combat by Paul Hill Activision has announced that Call of Duty: Mobile will see the launch of Season 6 “Gundams Arrive” on July 2 at 5PM Pacific Time. This major collaboration between the world’s most popular FPS franchise and the Gundam franchise will introduce a new, limited-time mode called Gundam Team Deathmatch where 8 players will face off 4v4 and pilot Gundam-themed operators such as Ethan - Freedom Gundam, Reaper - Sazabi Gundam, Proton - v Gundamo, Deathscythe Gundam (EW). When playing in this game mode, players will notice a switch from the usual first-person view to the third-person perspective. The new game mode will also feature specific abilities and weapons that are unique to Gundam suits rather than player loadouts. The new Gundam Team Deathmatch mode will be played on a new map called interstellar space station, which has been designed for this mode. When playing, you’ll discover that the mech suits offer specialized mobility such as dodge, sprint, and vertical jets. In the post-match, players will be able to watch Gundam operator animations with unlockable rewards for viewing. You can unlock more animations by participating in Gundam Team Deathmatch, normal Multiplayer, and Battle Royale modes. There will also be Gundam-themed in-game events, such as Survival of the Fittest, which will give players free rewards like the new legendary weapon J358 — Fin Funnel v Gundam, Urban Tracker — Defense Force, Cyro Bomb — Haro (reskin), Emote — Haro Team, new camos, and more. Players will also be able to obtain a variety of items through Season 6 Battle Pass free and premium tiers, including sci-fi-themed Operators and Weapon Blueprints. Players on the free tier will get access to the bolt-action 3-Line Rifle based on a World War II design and is capable of inflicting high damage with high accuracy. Free tier players will also have the chance to earn other rewards such as Skins, Weapons Blueprints, Vault Coins, and more. Players looking to spend money can get the Premium Pass. These players will have a chance to get all of the content from Season 6 including tactical warriors like Silver — Chrome Dome Reskin, Misty — Science Pilot, Atlas — Dust Ranger, and The Marshal — Rock Hound; and Weapon Blueprints like the BP50 — Pathripper, Oden — Maevwat Technical, PDW-57 — Rocket Re-Entry, BY15 — Dark Moon, and the 3-Line Rifle — Geo Thermal Line, based on the new Season 6 weapon. There’s also Battle Pass Subscription which gives you additional monthly rewards along with a 10% boost to Player and Weapon XP, discount coupons, and limited discounts on 10x crate pulls. Activision also stated that Mythic Drops are returning to the Mythic store and that Battle Pass Vault is getting Season 9 — Zombies Are Back (2022) and Season 6 — Templar's Oath (2023).
    • I managed to buy the original Hellblade: Senua’s Sacrifice through the ps app on my phone even though it was not showing up in the ps store when browsing from my ps5 it was buggy but more or less O.K.ish to play… I wonder if this original added version is funny fixed up for ps5 play
    • Download old Windows Startup Sounds @ https://www.winhistory.de/more/winstart/winstart_en.htm
    • Surface Copilot+ PCs coming to classrooms from July 22, turbocharged with on-device AI by Paul Hill Microsoft has announced that it’s launching the new Surface Pro 12-inch and Surface Laptop 13-inch models specifically for education customers from July 22. The Redmond giant said that these devices are being launched as a direct response to feedback from educators who want practicality and ease of use in their diverse classrooms. These are both Copilot+ PCs so teachers and students will be able to leverage the latest AI features thanks to the dedicated Neural Processing Units (NPUs) that allow for on-device AI. The on-device AI, aside from delivering well-known features like Recall, will enable new education features such as a new app Microsoft is working on called Microsoft Learning Zone. Microsoft Learning Zone will allow teachers to create personalized lessons by adapting content from trusted sources like OpenStax, generating interactive games with Kahoot, and tracking students progress. Microsoft expects this to help teachers save time and deliver a more flexible and engaging classroom. Another AI feature that will be available is Click to Do. This lets students highlight text or images and get contextual help. It can be used to summarize a paragraph or explain a graph. To activate it, students can press the Windows key and click. This feature runs entirely on device so inputs to the AI are secure and you don’t need to ever worry about third-parties seeing. Finally, these devices will also have accessibility features such as Voice Access which lets you navigate with speech and Live Captions which provide real-time subtitles and translations for spoken content. These make the devices more inclusive for students with disabilities. Regarding security, these laptops come with the Microsoft Pluton security chip directly integrated into the processor for protecting sensitive data. It can protect data such as passwords and sign-ins, even if your device is stolen. Thanks to automatic Windows Updates, schools never need to worry about falling behind on updates either. With the impending demise of Windows 10 in mid-October, these Surface devices arrive just in time for schools looking for somewhere to upgrade to. Aside from AI features and security, Microsoft is also pushing other key features including easy repair with replacement components at the Microsoft Store and iFixit, their lightweight design and all-day battery life making them ideal for carrying and surviving the school day, and their compatibility with popular education apps such as TestNav, Google Classroom, Minecraft Education, and Adobe Express.
  • Recent Achievements

    • Rising Star
      Phillip0web went up a rank
      Rising Star
    • One Month Later
      Epaminombas earned a badge
      One Month Later
    • One Year In
      Bert Fershner earned a badge
      One Year In
    • Reacting Well
      ChrisOdinUK earned a badge
      Reacting Well
    • One Year In
      Steviant earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      546
    2. 2
      ATLien_0
      205
    3. 3
      +FloatingFatMan
      170
    4. 4
      Michael Scrip
      151
    5. 5
      Som
      131
  • Tell a friend

    Love Neowin? Tell a friend!