473,568 Members | 2,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Executing thread in correct context

My ultimate goal is to get something like "ping.exe" to re-direct it's
standardOutput in real time to an .aspx page.

I've been able to get this behavior to work just fine in a regular
console application. I execute the process and the output is re-
directed to a windows textbox.

Below is the code I'm using to do that:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click

executeTest()

End Sub

Public Sub executeTest()

Dim p As New System.Diagnost ics.Process()

p.StartInfo.Fil eName = "ping"
p.StartInfo.Arg uments = "www.yahoo. com"
p.StartInfo.Use ShellExecute = False
p.StartInfo.Red irectStandardOu tput = True

AddHandler p.OutputDataRec eived, AddressOf outputHandler

p.Start()

p.BeginOutputRe adLine()

p.Close()

Console.Write(" done")

End Sub
Public Delegate Sub AddTextCallback (ByVal strText As String)
Private Sub AddText(ByVal strText As String)

TextBox1.Text = TextBox1.Text & strText & Environment.New Line

End Sub

Private Sub outputHandler(B yVal sendingProcess As Object, _
ByVal outLine As System.Diagnost ics.DataReceive dEventArgs)

' Collect the sort command output.
If Not String.IsNullOr Empty(outLine.D ata) Then
Button1.Invoke( New AddTextCallback (AddressOf AddText), New
Object() {outLine.Data})
End If

End Sub
The key to code above for me was the "Button1.Invoke (...)" line.

On my .aspx page I have a webcontrol called "div1" that represents a
<div>. There is no such method called "Invoke" for this control.
Conceptually is there a way to invoke the delegate so that it runs in
the correct UI thread (whatever that thread is called)?

I've been reading like mad over the past few days about threads,
delegates, etc. so forgive my ignorance with terms etc. I've thought
also about creating a webservice to do this, but I'm not sure how to
return results in real time via the webservice. I can kick off the
process, but am not sure how to report the results back.

Mar 20 '07 #1
1 1371
html controls or server controls are not windows controls so they do not
*suffer* the threading issues inherent in windows controls; you won't find
invoke on them because they are implicitly thread safe. (not quite true,
they are more thread-unaware).

When you execute the thread, you will need to go *scrape* the output window,
parse the text and store it in a variable. From that point, it will be
available to server code assuming that you invoked the output window from
the server code.

It does seem that you are doing it the other way around, that is, given a
command you are trying to write to a page. That's not possible, since you
don't have a call context.

You can write a webservice and return the data from a web method, then call
this webservice from the web page.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
<ry******@gmail .comwrote in message
news:11******** *************@y 66g2000hsf.goog legroups.com...
My ultimate goal is to get something like "ping.exe" to re-direct it's
standardOutput in real time to an .aspx page.

I've been able to get this behavior to work just fine in a regular
console application. I execute the process and the output is re-
directed to a windows textbox.

Below is the code I'm using to do that:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click

executeTest()

End Sub

Public Sub executeTest()

Dim p As New System.Diagnost ics.Process()

p.StartInfo.Fil eName = "ping"
p.StartInfo.Arg uments = "www.yahoo. com"
p.StartInfo.Use ShellExecute = False
p.StartInfo.Red irectStandardOu tput = True

AddHandler p.OutputDataRec eived, AddressOf outputHandler

p.Start()

p.BeginOutputRe adLine()

p.Close()

Console.Write(" done")

End Sub
Public Delegate Sub AddTextCallback (ByVal strText As String)
Private Sub AddText(ByVal strText As String)

TextBox1.Text = TextBox1.Text & strText & Environment.New Line

End Sub

Private Sub outputHandler(B yVal sendingProcess As Object, _
ByVal outLine As System.Diagnost ics.DataReceive dEventArgs)

' Collect the sort command output.
If Not String.IsNullOr Empty(outLine.D ata) Then
Button1.Invoke( New AddTextCallback (AddressOf AddText), New
Object() {outLine.Data})
End If

End Sub
The key to code above for me was the "Button1.Invoke (...)" line.

On my .aspx page I have a webcontrol called "div1" that represents a
<div>. There is no such method called "Invoke" for this control.
Conceptually is there a way to invoke the delegate so that it runs in
the correct UI thread (whatever that thread is called)?

I've been reading like mad over the past few days about threads,
delegates, etc. so forgive my ignorance with terms etc. I've thought
also about creating a webservice to do this, but I'm not sure how to
return results in real time via the webservice. I can kick off the
process, but am not sure how to report the results back.

Mar 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1426
by: R. Rajesh Jeba Anbiah | last post by:
----------------------------------------------------------------- This is the FAQ thread where the FAQ compilation project goes. * If you wish to improve the contents, please copy the whole content, fix it and then post it. When posting, please change the revision number (increase by 1) in the subject line. * If you want to comment, do it...
0
1493
by: Janwillem Borleffs | last post by:
----------------------------------------------------------------- This is the FAQ thread where the FAQ compilation project goes. * If you wish to improve the contents, please copy the whole content, fix it and then post it. When posting, please change the revision number (increase by 1) in the subject line. * If you want to comment, do it...
0
1299
by: Janwillem Borleffs | last post by:
----------------------------------------------------------------- This is the FAQ thread where the FAQ compilation project goes. * If you wish to improve the contents, please copy the whole content, fix it and then post it. When posting, please change the revision number (increase by 1) in the subject line. * If you want to comment, do it...
0
1605
by: Janwillem Borleffs | last post by:
----------------------------------------------------------------- This is the FAQ thread where the FAQ compilation project goes. * If you wish to improve the contents, please copy the whole content, fix it and then post it. When posting, please change the revision number (increase by 1) in the subject line. * If you want to comment, do it...
3
2248
by: R. Rajesh Jeba Anbiah | last post by:
----------------------------------------------------------------- This is the FAQ thread where the FAQ compilation project goes. * If you wish to improve the contents, please copy the whole content, fix it and then post it. When posting, please change the revision number (increase by 1) in the subject line. * If you want to comment, do it...
0
1483
by: BasicQ | last post by:
I am running an executable from my aspx page with the click of a button. A date is passed as an argument. I am able to get the standardoutput from the Process(Exe) into the label of my page after the process has completed executing. My problem is I need to get the output in the label simultaneously when the EXE is running, not after it has...
4
4215
by: Diffident | last post by:
Hi All, I am trying to perform a non-CPU bound operation in an asynchronous fashion using 'Thread' and a delegate. Basically, I am spawning a thread using ThreadStart and Thread. My non-CPU bound operation needs to have access to Session variables; Even though I embedded the state information (which also includes the context object) in...
5
5735
by: Brian | last post by:
I have an file based asp.net application the creates a thread to do some background printing. It works fine but when the application is deployed on a web server, the following error occurs in the thread when it accesses SQL: Login failed for user ''. The user is not associated with a trusted SQL Server connection. Note the blank user. It...
2
1988
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I am executing an AJAX page method that is a long running task. After starting the first method, I execute a second page method to retrieve the status of the task. It works fine in an empty web application, but when I paste the code into my main application (~10 projects, maybe 100 files) the behavior changes. What happens is the second page...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.