# VB.net - How do I keep an application's UI responsive while it does something?

**URL:** <https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297>\
**Category:** Factual Questions\
**Created:** [April 7, 2009, 8:33pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297 "2009-04-07T20:33:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [April 7, 2009, 8:33pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/1 "2009-04-07T20:33:00Z")

</div>

I’m writing a very simple program that says whatever you type into a textbox out loud (background [here](http://boards.straightdope.com/sdmb/showthread.php?t=513255)). It’s written in [VB.net](http://VB.net) 2008 Express and uses Vista’s built-in text-to-speech capabilities. Source code [here](http://drop.io/egdhaol).

Whenever I push the button to make it talk, the program freezes until the speech is complete. How can I make it stay active so I can continue typing new sentences into a queue?

Does it have anything to do with Application.DoEvents() or multi-threading? I know I’ve done this before, but I don’t remember how and that was way before .NET anyway. Is there a proper/better way to do this nowadays?

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)\
**Post date:** [April 7, 2009, 9:01pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/2 "2009-04-07T21:01:48Z")

</div>

Threading is the way to do it. When you push the button to make it talk, you want to make a new thread and put the talk code in there.

It’s not too hard, but there’s a few tricks to it. Any decent .Net book should have sample code to walk you through it.

---

<div class="post-metadata">

**Author:** ![Cerowyn](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@Cerowyn](https://boards.straightdope.com/u/Cerowyn)\
**Post date:** [April 8, 2009, 12:30am UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/3 "2009-04-08T00:30:52Z")

</div>

Here’s an article about using .NET’s worker thread pool that may help with Athena’s suggestion: [http://msdn.microsoft.com/en-us/netframework/cc949108.aspx](http://msdn.microsoft.com/en-us/netframework/cc949108.aspx).

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [April 8, 2009, 12:53am UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/4 "2009-04-08T00:53:08Z")

</div>

[rant]Glatrhgagasfgisadfsafeehatehatehatevideos. And THE MONSTROSITY THAT IS SILVERLIGHT! There was nothing wrong with animated .GIFs!!! BRING BACK GOPHER!!!  
[/rant]

Ahem. I will investigate this newfangled threadpool thing and hopefully make it work. Thank you both 🙂

And hey, if anyone wants to go ahead and put in some sample code for making a simple multithreaded app… 😃 (I tried Googling, but there is sooooo much out there that it’s hard to find something for the most recent version).

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [April 8, 2009, 1:16am UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/5 "2009-04-08T01:16:11Z")

</div>

:smack:  
Heh, I just used the SpeakAsync method instead of Speak and .NET handled the rest automatically.

Sometimes I actually love Microsoft. Please don’t shoot me.

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [April 8, 2009, 3:12am UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/6 "2009-04-08T03:12:17Z")

</div>

Yep, they thought of that. .Net rocks.

---

<div class="post-metadata">

**Author:** ![Athena](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@Athena](https://boards.straightdope.com/u/Athena)\
**Post date:** [April 8, 2009, 12:07pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/7 "2009-04-08T12:07:15Z")

</div>

Say what you will about Microsoft, their development tools & APIs rock. I only wish web development was as sophisticated as windows form development was in, say, 1992. But the horror that is HTML persists…

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [April 8, 2009, 6:55pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/8 "2009-04-08T18:55:54Z")

</div>

> [@Athena](#):
>
> Say what you will about Microsoft, their development tools & APIs rock. I only wish web development was as sophisticated as windows form development was in, say, 1992. But the horror that is HTML persists…

Say, how is .NET web development these days?

Does Microsoft’s promise of “write once, deploy everywhere (meaning on the web and all Windows versions)” ring true or is that just empty propaganda?

How difficult is it to take, say, a Windows Forms application and transfer it to the web? How is the UI difference between Windows and HTML handled, for example? And what’s this fancy schmancy WPF thing? Is that just another name for “make your app as glassy as Aero!” or does it actually help in cross-platform interface drawing?

I grew up on LAMP _and_ Visual Studio, but the sheer bliss that is the VS IDE is something Dreamweaver et al. can only dream of.

---

<div class="post-metadata">

**Author:** ![Cerowyn](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@Cerowyn](https://boards.straightdope.com/u/Cerowyn)\
**Post date:** [April 8, 2009, 9:55pm UTC](https://boards.straightdope.com/t/vb-net-how-do-i-keep-an-applications-ui-responsive-while-it-does-something/492297/9 "2009-04-08T21:55:56Z")

</div>

VS2008 makes earlier versions seem like Wordpad, in truth. It is the current pinnacle of development environments; I mean, I like Eclipse, especially the version that Adobe has banged into Flex Builder, but it still pales in comparison to VS2008.

There are a lot of parallels between [ASP.NET](http://ASP.NET) and Windows Forms, these days. They have gone a long way to make them functionally similar, especially with the controls like grids and views. Even the paradigm, with the code-behind files that were introduced in the original [ASP.NET](http://ASP.NET) approach, is very similar to Forms. And, with things like login in and user control now extended to Windows Forms (for which you still need to create a web service), the architecture can be shared to a great degree between a web application and a Forms application. Nonetheless, there are still a great many differences between the two. [ASP.NET](http://ASP.NET) is too deeply entrenched in the web/HTML paradigm to really be easily interoperable with Forms applications.
