2

I am new to coding and for one of my first projects I have to read information from a digital caliper and display it in a text box on a web application. I found code from another project some else created where they are using a windows form. I am using visual studio 2013 and I am modifying their code to work with a web application instead of a windows form. The trouble I am having is that they have two lines of code that I do not understand and cannot seem to find an answer of how to modify them to work for my needs. the code is

this.BeginInvoke(new EventHandler(delegate { SetTheText(strErg); }));
Application.DoEvents();

The problem is that both BeginInvoke and DoEvents() have an error saying there is no definition for either. Is there a way to modify this to a web application? Or is there a way to make the definition know for both of these?

It may seem trivial to many but I cannot figure it out. Any help would be greatly appreciated!

I have the following using statements included using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Threading; using System.IO.Ports; using Telerik.Web.UI; using System.Windows.Forms; using System.Web.Services.Protocols; using System.Web.Services

;

Guy Hendrickson
  • 87
  • 1
  • 1
  • 8
  • What do you have for `using` statements at the top of the file? Does it include [`System.Windows.Forms`](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.begininvoke(v=vs.110).aspx)? – gunr2171 Jul 21 '14 at 20:10
  • @gunr2171 yes I have using system.windows.forms. I will edit my post to include all of my using statements. – Guy Hendrickson Jul 21 '14 at 20:20

1 Answers1

3

These are not applicable to a web application.

Unlike web apps, windows apps need to have a Main or GUI Thread. Which means you often have to use BeginInvoke to marshall a command onto that thread.

DoEvents was used in VB 6 to simulate multi-threading. It really isn't necessary for modern windows apps, especially now that we have async/await. Usually people call DoEvents to repaint the screen, which isn't applicable for a web app.

So in conclusion, you don't need them. Just call SetTheText directly.

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
  • Okay that makes sense. The code did look a bit outdated. I was hoping that this was the problem with my program not running but I took these lines out and it still doesn't seem to want to work. I'll just keep trying different things to figure it out. Thanks for your help! – Guy Hendrickson Jul 21 '14 at 20:29