PC Review


Reply
Thread Tools Rate Thread

how to create Thread?

 
 
Adda
Guest
Posts: n/a
 
      8th Apr 2004
I have an mdi form and I am trying to call a procedure -
"myTest" in the parent from the childform. I am
experimenting using a thread, but the thread is not
releasing the childform. I place a breakpoint in "myTest"
on the parent form and I have a
msgbox("Done here!") on the childform. The program stops
at the breakpoint in "myTest" but does not continue to the
msgbox until after I have finished with "myTest". Here is
what I have in the childform:
----------------------------------------------
Imports System
Imports System.Threading
....
Public Class childfrm

Private Sub btn_Click(...)...
Dim p As New frmParent
Dim t As New Thread(AddressOf p.myTest())
t.Start()
MsgBox("done here!")
End Sub
End Class
------------------------------------------------
"myTest" runs OK, but not reaching msgbox in childform
until "myTest" is done first.

I also get this message in the output window after running
everything:

The thread '<No Name>' (0xb48) has exited with code 0
(0x0).

Am I using the Thread object correctly? Could someone
tell me how to use Threading correctly here?

TIA
Adda
 
Reply With Quote
 
 
 
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      8th Apr 2004
Hi,

Why are you creating a new frmparent. Why dont you try

Dim p as frmParent = Me.Parent

Ken
-------------------
"Adda" <(E-Mail Removed)> wrote in message
news:1a39901c41db1$06695600$(E-Mail Removed)...
> I have an mdi form and I am trying to call a procedure -
> "myTest" in the parent from the childform. I am
> experimenting using a thread, but the thread is not
> releasing the childform. I place a breakpoint in "myTest"
> on the parent form and I have a
> msgbox("Done here!") on the childform. The program stops
> at the breakpoint in "myTest" but does not continue to the
> msgbox until after I have finished with "myTest". Here is
> what I have in the childform:
> ----------------------------------------------
> Imports System
> Imports System.Threading
> ...
> Public Class childfrm
>
> Private Sub btn_Click(...)...
> Dim p As New frmParent
> Dim t As New Thread(AddressOf p.myTest())
> t.Start()
> MsgBox("done here!")
> End Sub
> End Class
> ------------------------------------------------
> "myTest" runs OK, but not reaching msgbox in childform
> until "myTest" is done first.
>
> I also get this message in the output window after running
> everything:
>
> The thread '<No Name>' (0xb48) has exited with code 0
> (0x0).
>
> Am I using the Thread object correctly? Could someone
> tell me how to use Threading correctly here?
>
> TIA
> Adda



 
Reply With Quote
 
Adda
Guest
Posts: n/a
 
      8th Apr 2004
Hi Ken,

I actually tried something like that a few days ago but
could not get the correct syntax (still in the migration
process from vb6). So I tried it with your syntax, but I
was having an implicit conversion problem since I had
Option Strict On. So I turned it off. Now I get an error
that the specified cast is not valid. So I tried

Dim p as frmParent = CType(Me.Parent,
System.Windows.Forms.Form)

but still having problem with specified cast not valid. I
appologize for my newbieness with .Net (just know that I
hate having to go through the amateur phase all over
again .

Adda

>-----Original Message-----
>Hi,
>
> Why are you creating a new frmparent. Why dont

you try
>
>Dim p as frmParent = Me.Parent
>
>Ken
>-------------------
>"Adda" <(E-Mail Removed)> wrote in

message
>news:1a39901c41db1$06695600$(E-Mail Removed)...
>> I have an mdi form and I am trying to call a procedure -
>> "myTest" in the parent from the childform. I am
>> experimenting using a thread, but the thread is not
>> releasing the childform. I place a breakpoint

in "myTest"
>> on the parent form and I have a
>> msgbox("Done here!") on the childform. The program

stops
>> at the breakpoint in "myTest" but does not continue to

the
>> msgbox until after I have finished with "myTest". Here

is
>> what I have in the childform:
>> ----------------------------------------------
>> Imports System
>> Imports System.Threading
>> ...
>> Public Class childfrm
>>
>> Private Sub btn_Click(...)...
>> Dim p As New frmParent
>> Dim t As New Thread(AddressOf p.myTest())
>> t.Start()
>> MsgBox("done here!")
>> End Sub
>> End Class
>> ------------------------------------------------
>> "myTest" runs OK, but not reaching msgbox in childform
>> until "myTest" is done first.
>>
>> I also get this message in the output window after

running
>> everything:
>>
>> The thread '<No Name>' (0xb48) has exited with code 0
>> (0x0).
>>
>> Am I using the Thread object correctly? Could someone
>> tell me how to use Threading correctly here?
>>
>> TIA
>> Adda

>
>
>.
>

 
Reply With Quote
 
Sameh Ahmed
Guest
Posts: n/a
 
      9th Apr 2004
Hello Adda
Try Dim p as NEW frmParent = CType(Me.Parent, System.Windows.Forms.Form)
"Adda" <(E-Mail Removed)> wrote in message
news:15b7b01c41dbb$286eb3d0$(E-Mail Removed)...
> Hi Ken,
>
> I actually tried something like that a few days ago but
> could not get the correct syntax (still in the migration
> process from vb6). So I tried it with your syntax, but I
> was having an implicit conversion problem since I had
> Option Strict On. So I turned it off. Now I get an error
> that the specified cast is not valid. So I tried
>
> Dim p as frmParent = CType(Me.Parent,
> System.Windows.Forms.Form)
>
> but still having problem with specified cast not valid. I
> appologize for my newbieness with .Net (just know that I
> hate having to go through the amateur phase all over
> again .
>
> Adda
>
> >-----Original Message-----
> >Hi,
> >
> > Why are you creating a new frmparent. Why dont

> you try
> >
> >Dim p as frmParent = Me.Parent
> >
> >Ken
> >-------------------
> >"Adda" <(E-Mail Removed)> wrote in

> message
> >news:1a39901c41db1$06695600$(E-Mail Removed)...
> >> I have an mdi form and I am trying to call a procedure -
> >> "myTest" in the parent from the childform. I am
> >> experimenting using a thread, but the thread is not
> >> releasing the childform. I place a breakpoint

> in "myTest"
> >> on the parent form and I have a
> >> msgbox("Done here!") on the childform. The program

> stops
> >> at the breakpoint in "myTest" but does not continue to

> the
> >> msgbox until after I have finished with "myTest". Here

> is
> >> what I have in the childform:
> >> ----------------------------------------------
> >> Imports System
> >> Imports System.Threading
> >> ...
> >> Public Class childfrm
> >>
> >> Private Sub btn_Click(...)...
> >> Dim p As New frmParent
> >> Dim t As New Thread(AddressOf p.myTest())
> >> t.Start()
> >> MsgBox("done here!")
> >> End Sub
> >> End Class
> >> ------------------------------------------------
> >> "myTest" runs OK, but not reaching msgbox in childform
> >> until "myTest" is done first.
> >>
> >> I also get this message in the output window after

> running
> >> everything:
> >>
> >> The thread '<No Name>' (0xb48) has exited with code 0
> >> (0x0).
> >>
> >> Am I using the Thread object correctly? Could someone
> >> tell me how to use Threading correctly here?
> >>
> >> TIA
> >> Adda

> >
> >
> >.
> >



 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      9th Apr 2004
Hi,

Dim p as frmParent = CType(Me.Parent, frmParent)

Ken
---------------------
"Adda" <(E-Mail Removed)> wrote in message
news:15b7b01c41dbb$286eb3d0$(E-Mail Removed)...
> Hi Ken,
>
> I actually tried something like that a few days ago but
> could not get the correct syntax (still in the migration
> process from vb6). So I tried it with your syntax, but I
> was having an implicit conversion problem since I had
> Option Strict On. So I turned it off. Now I get an error
> that the specified cast is not valid. So I tried
>
> Dim p as frmParent = CType(Me.Parent,
> System.Windows.Forms.Form)
>
> but still having problem with specified cast not valid. I
> appologize for my newbieness with .Net (just know that I
> hate having to go through the amateur phase all over
> again .
>
> Adda
>
> >-----Original Message-----
> >Hi,
> >
> > Why are you creating a new frmparent. Why dont

> you try
> >
> >Dim p as frmParent = Me.Parent
> >
> >Ken
> >-------------------
> >"Adda" <(E-Mail Removed)> wrote in

> message
> >news:1a39901c41db1$06695600$(E-Mail Removed)...
> >> I have an mdi form and I am trying to call a procedure -
> >> "myTest" in the parent from the childform. I am
> >> experimenting using a thread, but the thread is not
> >> releasing the childform. I place a breakpoint

> in "myTest"
> >> on the parent form and I have a
> >> msgbox("Done here!") on the childform. The program

> stops
> >> at the breakpoint in "myTest" but does not continue to

> the
> >> msgbox until after I have finished with "myTest". Here

> is
> >> what I have in the childform:
> >> ----------------------------------------------
> >> Imports System
> >> Imports System.Threading
> >> ...
> >> Public Class childfrm
> >>
> >> Private Sub btn_Click(...)...
> >> Dim p As New frmParent
> >> Dim t As New Thread(AddressOf p.myTest())
> >> t.Start()
> >> MsgBox("done here!")
> >> End Sub
> >> End Class
> >> ------------------------------------------------
> >> "myTest" runs OK, but not reaching msgbox in childform
> >> until "myTest" is done first.
> >>
> >> I also get this message in the output window after

> running
> >> everything:
> >>
> >> The thread '<No Name>' (0xb48) has exited with code 0
> >> (0x0).
> >>
> >> Am I using the Thread object correctly? Could someone
> >> tell me how to use Threading correctly here?
> >>
> >> TIA
> >> Adda

> >
> >
> >.
> >



 
Reply With Quote
 
Adda
Guest
Posts: n/a
 
      9th Apr 2004
Well, I tried this but still getting the casting problem.
The only thing that is working here is

Dim p as New frmParent

My goal is to be able to refresh the datagrid in the
parent form from the childform. I'm sure there is a way,
but I just don't have the proficiency yet with vb.net to
intuit how to accomplish this. Maybe API code? It seems
like only adding data to the dataset from the parent form
does the trick. How can I trick the parent form from the
childform? Oh well, back to the drawing board.

But I thank everyone for all the replies and suggestions.

Adda

>-----Original Message-----
>Hi,
>
>Dim p as frmParent = CType(Me.Parent, frmParent)
>
>Ken
>---------------------
>"Adda" <(E-Mail Removed)> wrote in

message
>news:15b7b01c41dbb$286eb3d0$(E-Mail Removed)...
>> Hi Ken,
>>
>> I actually tried something like that a few days ago but
>> could not get the correct syntax (still in the migration
>> process from vb6). So I tried it with your syntax, but

I
>> was having an implicit conversion problem since I had
>> Option Strict On. So I turned it off. Now I get an

error
>> that the specified cast is not valid. So I tried
>>
>> Dim p as frmParent = CType(Me.Parent,
>> System.Windows.Forms.Form)
>>
>> but still having problem with specified cast not

valid. I
>> appologize for my newbieness with .Net (just know that I
>> hate having to go through the amateur phase all over
>> again .
>>
>> Adda
>>
>> >-----Original Message-----
>> >Hi,
>> >
>> > Why are you creating a new frmparent. Why

dont
>> you try
>> >
>> >Dim p as frmParent = Me.Parent
>> >
>> >Ken
>> >-------------------
>> >"Adda" <(E-Mail Removed)> wrote in

>> message
>> >news:1a39901c41db1$06695600$(E-Mail Removed)...
>> >> I have an mdi form and I am trying to call a

procedure -
>> >> "myTest" in the parent from the childform. I am
>> >> experimenting using a thread, but the thread is not
>> >> releasing the childform. I place a breakpoint

>> in "myTest"
>> >> on the parent form and I have a
>> >> msgbox("Done here!") on the childform. The program

>> stops
>> >> at the breakpoint in "myTest" but does not continue

to
>> the
>> >> msgbox until after I have finished with "myTest".

Here
>> is
>> >> what I have in the childform:
>> >> ----------------------------------------------
>> >> Imports System
>> >> Imports System.Threading
>> >> ...
>> >> Public Class childfrm
>> >>
>> >> Private Sub btn_Click(...)...
>> >> Dim p As New frmParent
>> >> Dim t As New Thread(AddressOf p.myTest())
>> >> t.Start()
>> >> MsgBox("done here!")
>> >> End Sub
>> >> End Class
>> >> ------------------------------------------------
>> >> "myTest" runs OK, but not reaching msgbox in

childform
>> >> until "myTest" is done first.
>> >>
>> >> I also get this message in the output window after

>> running
>> >> everything:
>> >>
>> >> The thread '<No Name>' (0xb48) has exited with code 0
>> >> (0x0).
>> >>
>> >> Am I using the Thread object correctly? Could

someone
>> >> tell me how to use Threading correctly here?
>> >>
>> >> TIA
>> >> Adda
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      9th Apr 2004
Hi Adda,

I was curious if this would work.

I think that it does as you wanted?

(Most code is to build the sample table)

Cor

\\\Mdiform
Private Sub FormMdi_Load(ByVal _
sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
dt.CreateTable()
Dim frm1 As New Form1
frm1.MdiParent = Me
frm1.Show()
Dim frm2 As New Form2
frm2.MdiParent = Me
frm2.Show()
AddHandler dt.dvchanged, AddressOf myrefresh
End Sub
Private Sub myrefresh()
Me.Refresh()
End Sub
///
\\\2 forms form1 and form2 both the same
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = dt.dv
End Sub
///
\\\Class to build a sample table as and to set the events
Public Class dt
Public Shared WithEvents dv As DataView
Public Shared Event dvchanged()
Public Shared Sub CreateTable()
Dim dt As New DataTable("Sample")
For i As Integer = 0 To 7
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
For i As Integer = 0 To 8
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = (Chr(i + 48))
Next
Next
dv = New DataView(dt)
End Sub
Private Shared Sub dv_ListChanged(ByVal sender _
As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) _
Handles dv.ListChanged
RaiseEvent dvchanged()
End Sub
End Class
///


 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      9th Apr 2004
Hi,

Dim p as frmParent = DirectCast(Me.MdiParent, frmParent)

Ken
--------------
"Adda" <(E-Mail Removed)> wrote in message
news:1784801c41def$5e97c350$(E-Mail Removed)...
> Well, I tried this but still getting the casting problem.
> The only thing that is working here is
>
> Dim p as New frmParent
>
> My goal is to be able to refresh the datagrid in the
> parent form from the childform. I'm sure there is a way,
> but I just don't have the proficiency yet with vb.net to
> intuit how to accomplish this. Maybe API code? It seems
> like only adding data to the dataset from the parent form
> does the trick. How can I trick the parent form from the
> childform? Oh well, back to the drawing board.
>
> But I thank everyone for all the replies and suggestions.
>
> Adda
>
> >-----Original Message-----
> >Hi,
> >
> >Dim p as frmParent = CType(Me.Parent, frmParent)
> >
> >Ken
> >---------------------
> >"Adda" <(E-Mail Removed)> wrote in

> message
> >news:15b7b01c41dbb$286eb3d0$(E-Mail Removed)...
> >> Hi Ken,
> >>
> >> I actually tried something like that a few days ago but
> >> could not get the correct syntax (still in the migration
> >> process from vb6). So I tried it with your syntax, but

> I
> >> was having an implicit conversion problem since I had
> >> Option Strict On. So I turned it off. Now I get an

> error
> >> that the specified cast is not valid. So I tried
> >>
> >> Dim p as frmParent = CType(Me.Parent,
> >> System.Windows.Forms.Form)
> >>
> >> but still having problem with specified cast not

> valid. I
> >> appologize for my newbieness with .Net (just know that I
> >> hate having to go through the amateur phase all over
> >> again .
> >>
> >> Adda
> >>
> >> >-----Original Message-----
> >> >Hi,
> >> >
> >> > Why are you creating a new frmparent. Why

> dont
> >> you try
> >> >
> >> >Dim p as frmParent = Me.Parent
> >> >
> >> >Ken
> >> >-------------------
> >> >"Adda" <(E-Mail Removed)> wrote in
> >> message
> >> >news:1a39901c41db1$06695600$(E-Mail Removed)...
> >> >> I have an mdi form and I am trying to call a

> procedure -
> >> >> "myTest" in the parent from the childform. I am
> >> >> experimenting using a thread, but the thread is not
> >> >> releasing the childform. I place a breakpoint
> >> in "myTest"
> >> >> on the parent form and I have a
> >> >> msgbox("Done here!") on the childform. The program
> >> stops
> >> >> at the breakpoint in "myTest" but does not continue

> to
> >> the
> >> >> msgbox until after I have finished with "myTest".

> Here
> >> is
> >> >> what I have in the childform:
> >> >> ----------------------------------------------
> >> >> Imports System
> >> >> Imports System.Threading
> >> >> ...
> >> >> Public Class childfrm
> >> >>
> >> >> Private Sub btn_Click(...)...
> >> >> Dim p As New frmParent
> >> >> Dim t As New Thread(AddressOf p.myTest())
> >> >> t.Start()
> >> >> MsgBox("done here!")
> >> >> End Sub
> >> >> End Class
> >> >> ------------------------------------------------
> >> >> "myTest" runs OK, but not reaching msgbox in

> childform
> >> >> until "myTest" is done first.
> >> >>
> >> >> I also get this message in the output window after
> >> running
> >> >> everything:
> >> >>
> >> >> The thread '<No Name>' (0xb48) has exited with code 0
> >> >> (0x0).
> >> >>
> >> >> Am I using the Thread object correctly? Could

> someone
> >> >> tell me how to use Threading correctly here?
> >> >>
> >> >> TIA
> >> >> Adda
> >> >
> >> >
> >> >.
> >> >

> >
> >
> >.
> >



 
Reply With Quote
 
Adda
Guest
Posts: n/a
 
      12th Apr 2004
Thank you. This is an interesting approach. I did try it
and got a message that an mdiparent can't be a parent and
also a child. I will experiment with this. Here is the
truth. I am taking a class in ADO.net using VB.net (or
C#). The instructor has a solution, but I won't know it
(until it is too late . The only thing I can really
think of to evoke something in the parent form would be to
show the childform as a dialog form. But I tried that
only to get the message that only top level forms can be
showed as dialog. In the meantime, I can always read the
contents of the childform from a menu on the parent form.
My instructions are not completely clear (to me) but the
idea is that I add data to a dataset on the parent form
but by clicking a button on the childform and on the
update (from the childform) the datagrid gets refreshed
(also from the button click on the childform).

Adda




>-----Original Message-----
>Hi Adda,
>
>I was curious if this would work.
>
>I think that it does as you wanted?
>
>(Most code is to build the sample table)
>
>Cor
>
>\\\Mdiform
> Private Sub FormMdi_Load(ByVal _
> sender As Object, ByVal e As System.EventArgs) _
> Handles MyBase.Load
> dt.CreateTable()
> Dim frm1 As New Form1
> frm1.MdiParent = Me
> frm1.Show()
> Dim frm2 As New Form2
> frm2.MdiParent = Me
> frm2.Show()
> AddHandler dt.dvchanged, AddressOf myrefresh
>End Sub
>Private Sub myrefresh()
> Me.Refresh()
>End Sub
>///
>\\\2 forms form1 and form2 both the same
> Private Sub Form1_Load(ByVal sender As Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> DataGrid1.DataSource = dt.dv
>End Sub
>///
>\\\Class to build a sample table as and to set the events
>Public Class dt
> Public Shared WithEvents dv As DataView
> Public Shared Event dvchanged()
> Public Shared Sub CreateTable()
> Dim dt As New DataTable("Sample")
> For i As Integer = 0 To 7
> Dim dc As New DataColumn(Chr(i + 65))
> dt.Columns.Add(dc)
> Next
> For i As Integer = 0 To 8
> dt.Rows.Add(dt.NewRow)
> For y As Integer = 0 To dt.Columns.Count - 1
> dt.Rows(i)(y) = (Chr(i + 48))
> Next
> Next
> dv = New DataView(dt)
>End Sub
>Private Shared Sub dv_ListChanged(ByVal sender _
> As Object, ByVal e As

System.ComponentModel.ListChangedEventArgs) _
> Handles dv.ListChanged
> RaiseEvent dvchanged()
> End Sub
>End Class
>///
>
>
>.
>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      12th Apr 2004
Hi Adda,

I did test that sample and did not get an error, did you set the mdi = true
in the mdi form that I did using the designer?

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a window on a non UI thread within a C++\Clr? BartMan Microsoft VC .NET 0 31st Jul 2008 04:09 PM
ShowDialog - Cross-thread operation not valid: Control'CheckAccountInfo' accessed from a thread other than the thread it was createdon. Tom C Microsoft C# .NET 9 20th Feb 2008 08:15 PM
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on Joe Microsoft C# .NET 4 12th Mar 2007 09:59 AM
VB.Net Create a new thread Ron Weiner Microsoft Dot NET Compact Framework 2 28th Apr 2006 03:36 PM
How can create this thread? help me ,thank thank thank qushui_chen Microsoft C# .NET 1 9th Dec 2003 08:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:32 PM.