2
votes

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

;

1
What do you have for using statements at the top of the file? Does it include System.Windows.Forms?gunr2171
@gunr2171 yes I have using system.windows.forms. I will edit my post to include all of my using statements.Guy Hendrickson

1 Answers

3
votes

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.