hi all,
i have a program with MDI parent and child. initially, the program will call a child e.g. ChildMain. on this child form, 2 processes are run. the 2nd is ran on a backgroundworker. the backgroundworkder in created through code. the process in the background worker is to create another childform but i'm having problem setting the MDIParent of this child form since VS is saying some sort of cross-thread issue.
below are the codes i'm using.
if i use the following codes it works but i need to set the text on a different richtextbox on a different child form.Code:Imports Microsoft.VisualBasic Imports System.Net.NetworkInformation Public Class CHILDMAIN Dim strRTOTime As String Private _Host As String Public Delegate Sub setTextCallback(ByVal value As String) Public Property Host() Get Return _Host End Get Set(ByVal value) _Host = value End Set End Property Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Try Dim strLine As String = String.Empty Dim strTime As String = Format(Now, "MM-dd-yyyy hh.mm.ss") Dim Ping As New Ping Dim PingOptions As New PingOptions PingOptions.Ttl = 64 Dim PingReply As PingReply = Ping.Send(_Host, 500) If PingReply.Status = IPStatus.Success Then strLine = strTime & " Reply from " & _Host & ": bytes=" & PingReply.Buffer.Length & " time=" & PingReply.RoundtripTime & "ms TTL=" & PingReply.Options.Ttl & vbNewLine Else strLine = strTime & " Request timed out" & vbNewLine strRTOTime = strTime Timer1.Stop() Dim bgwTemp As New System.ComponentModel.BackgroundWorker AddHandler bgwTemp.DoWork, AddressOf DoWork AddHandler bgwTemp.RunWorkerCompleted, AddressOf RunWorkerCompleted bgwTemp.RunWorkerAsync() bgwTemp.Dispose() End If rtbLog.AppendText(strLine) Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Dim LogForm As New LOG LogForm.MdiParent = Me.MdiParent LogForm.RichTextBox1.AppendText(ReturnShellResults("tracert.exe", _Host)) LogForm.Show() 'setText(vbNewLine) 'setText("Trace Route " & _Host & vbNewLine) 'setText("--------------------------------------------------" & vbNewLine) 'setText(ReturnShellResults("tracert.exe", _Host)) 'setText("--------------------------------------------------" & vbNewLine) 'setText(vbNewLine) End Sub Private Sub RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Timer1.Start() End Sub Private Sub setText(ByVal value As String) If rtbLog.InvokeRequired Then rtbLog.Invoke(New setTextCallback(AddressOf setText), value) Else rtbLog.AppendText(value) End If End Sub
please help me.Code:setText(vbNewLine) setText("Trace Route " & _Host & vbNewLine) setText("--------------------------------------------------" & vbNewLine) setText(ReturnShellResults("tracert.exe", _Host)) setText("--------------------------------------------------" & vbNewLine) setText(vbNewLine)
thanks.




Reply With Quote