|
Is there any way possible in a windows application project to kill the default current thread of the project and run a new thread and then relate the project to it?
My case scenario:-
I have a startup form. In its Load event I want to kill the current thread, create a new thread and run the project through the new thread. This'll be applicable in closing the startup form and open another form. When I run, the new thread is being created, everything is ok. But as soon as the default/current thread is being killed the application is closing down. How can I tackle this? Provided, I don't want to hide the startup form or stuffs like that.
Plz help. Regards.
|
|
|
|
|
i think there's other options but i'll give you want you ask for.
you would need to start a second message loop. so in the routine that's called when you start the new thread. do an application.run(your main form) in there. then close your startup form and the first message loop will killed.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
nlarson11 wrote: i think there's other options but i'll give you want you ask for.
you would need to start a second message loop. so in the routine that's called when you start the new thread. do an application.run(your main form) in there. then close your startup form and the first message loop will killed.
Hi nlarson11, I did it ur way. It works great. But i tried to change it a bit. Here's my code:
Imports System.Threading
Public Class frmStartup
Private Sub frmStartup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim OldThread As Thread
Dim NewThread As Thread
Try
OldThread = Thread.CurrentThread
NewThread = New Thread(AddressOf NewThreadMethod)
NewThread.Start()
OldThread.Abort()
'Me.Close()
Catch tae as ThreadAbortException
'Do nothing.
Catch ex As Exception
MsgBox(ex.Message, , "frmStartup_Load")
End Try
End Sub
Private Sub NewThreadMethod()
Try
Application.Run(New frmAnother)
Catch ex As Exception
MsgBox(ex.Message, , "NewThreadMethod")
End Try
End Sub
End Class
U told me to close the startup form after starting the new thread. When I do that everything is fine. But instead, as I tried to terminate the old thread explicitly, When I run it from the IDE it seems to be ok but when I execute the app by clicking the exe only, it throws ThreadAbortException though I'm catching it. The problem stays even if I uncomment Me.Close() and use it with OldThread.Abort(). So is it mandatory that I'm limited to close frmStartup only and can't terminate the old thread explicitly without the exception being thrown? Looking 4ward 4 ur further advice. Thanks 4 ur help.
|
|
|
|
|
priyamtheone wrote: But as soon as the default/current thread is being killed the application is closing down. How can I tackle this?
Of course. The app's message pump is running in it, which you can't move to another thread.
Are you tryingt o do something like a Login form? Showing the login form, then starting your real main form??
|
|
|
|
|
That's correct u can assume it as a login form or a splash form. First I'll show it and then I want to show the main form. Here's a brief summary:
As we have seen, if u try to treat a startup
form as a splash form and try to close it and
goto the 2nd form the application closes down.
If u try to do this by writing the following
code in the startup form:
Application.Run(frm2ndForm);
this.Close();
It'll give an error message something like
'More than one message cann't be
passed/processed through a single thread. Try
using frm2ndForm.ShowDialog();'. Keeping this
in mind I'm trying to close the initial thread
in which frmStartup is running, create and run
a new thread and then open frm2ndForm from it.
Hope u understand. Looking forward 4 ur reply.
Thanx.
N.B.- nlarson11's answer is pretty close to what I want.
|
|
|
|
|
I have a clarification to finish this task. When I send from my computer ie. dave@hiscompany.com
password: dave working fine.
Same program when I tested with other system, but same login,same password,same domain [dave@hiscompany.com & only computer name different] it's not working.......any ideas to solve this problem...?
Really what I planned, to use 1-user name & Password, for this purpose with all machines...
is it possible?
I mean, the user login will be different, from the program I want to supply another user network credentials...Is it possible?
Anybody can show me the code?
Thanks
|
|
|
|
|
is the other computer on the same network?
does the other computer have access to the same smtp server the first computer did?
is the other computer blocking port 25?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
yah, same network under same domain. But it's a laptop, that machine is desktop.No other difference.
Even I tried the same user id,password. with same lan. May be laptop port no will be different?
How to identify that?
Thanks...
|
|
|
|
|
port no 25 is for SMTP only, check in your laptop is this port is blocked by any firwall or antivirus softwares.
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Hi all,
I'm new into the forum and I have a question for you. How can I use the Win API 'SetParent' under VB 2008 to open a secondary form into a picturebox on a primary form? I need this because I want simulate a MDI form. For VB6 I used the following code and It works fine:
'<<declaration>>
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'<<function>>
Public Function SetParentInRect(FormChild As Variant, FormParent As Variant)
On Error GoTo ErrorHandler
Dim lChild As Long
Dim lParent As Long
On Error Resume Next
If IsObject(FormChild) Then
lChild = CallByName(FormChild, "hwnd", VbGet)
If lChild = 0 Then Err.Raise 1000, , "Cannot obtain handle from formchild"
Else
lChild = CLng(FormChild)
End If
If IsObject(FormParent) Then
lParent = CallByName(FormParent, "hwnd", VbGet)
If lParent = 0 Then Err.Raise 1000, , "Cannot obtain handle from formparent"
If TypeName(FormParent) = "MdiMain" Then
lParent = FindWindowEx(lParent, 0&, "MDIClient", vbNullString)
End If
If TypeName(FormParent) = "frmMain" Then
lParent = FormParent.picContainer.hWnd
End If
Else
lParent = CLng(FormParent)
End If
If Not IsWindow(lChild) Then Err.Raise 1000, , "Invalid form Handle : " & lChild
If Not IsWindow(lParent) Then Err.Raise 1000, , "Invalid form Handle : " & lParent
SetParent lChild, lParent
If False Then
ErrorHandler:
Err.Raise Err.Number, IIf(Len(Err.Source) > 0, Err.Source & "->", "") & "clsParent", Err.Description
End If
End Function
The sencondary form have the follwing property:
startupposition = manual
borderstyle = none
windowsstate = maximized
Is there anyone can help me (to translate this function in VB 2008)?
Thanks a lot,
Filippo
|
|
|
|
|
something like this?
PictureBox1.Controls.Add(New Form2 With {.TopLevel = False, .Visible = True, .Dock = DockStyle.Fill})
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Yes! It works exactly as I need.
Thank you wery much for you suggestion!
Filippo
|
|
|
|
|
Readonly with Editor is not working as readonly after setting the image and it is working as readonly but not setting the iMage to picture
<[ReadOnly](True)> <Editor(GetType(ImageOpenFileDialog), GetType(System.Drawing.Design.UITypeEditor))> _
Public Property BackgroundPicture() As String
Public Class ImageOpenFileDialog
Inherits UITypeEditor
Dim openFileDialog As OpenFileDialog
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
openFileDialog = New OpenFileDialog()
openFileDialog.FileName = ""
openFileDialog.Filter = "JPEG Images|*.jpg|GIF Images|*.gif|Bitmaps|*.bmp"
openFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyPictures
If openFileDialog.ShowDialog() = DialogResult.OK Then
Return openFileDialog.FileName
End If
Return MyBase.EditValue(context, provider, value)
End Function
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
Return UITypeEditorEditStyle.Modal
End Function
End Class
I am creating a readonly Property and if i click i open the Images to select the image . as it is a readonly property i am not able to set teh image to picture box .
----------
Working on Visual Studio 2005 PropertyGrid .
I want to lock all the keys not to enter in the propertygrid at the Picture Property like in Visual Basic 6.0 after selecting the image . Only Delete has to work
PictureBox -- Picture Property -- (Bitmap) after setting the image
so that the user shouldnot change the value
Presently i got the (None) in this way . Now i want to set the ReadOnly and only Delete key has to work and i want to set the Picture to PictureBox.
|
|
|
|
|
Hi,
While trying to create a group of tables in msaccess using VB.NET ADOX, i am facing the error "System.Runtime.InteropServices.COMException...at ADOX.columns.Append(Object item, DatatypeEnum Type, Int32 DefinedSize)".
The coding is given below..
Public Function CreateAccessDatabaseandtables( _
ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim con As New ADODB.Connection
Dim cat As New ADOX.Catalog()
Dim ADOXtable As New ADOX.Table
Dim ADOXindex As New ADOX.Index
Try
Dim sCreateString As String
sCreateString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
DatabaseFullPath
cat.Create(sCreateString)
bAns = True
'cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabaseFullPath
con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabaseFullPath)
'name table, append fields to table
ADOXtable.Name = "ACN_CHARX"
ADOXtable.Columns.Append("LOGICAL_DB_NAME", ADOX.DataTypeEnum.adVarWChar, 32)
ADOXtable.Columns.Append("DIM_NAME", ADOX.DataTypeEnum.adVarWChar, 32)
ADOXtable.Columns.Append("CHARX_NAME", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("CHARX_SEQ", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("CHARX_TYPE", ADOX.DataTypeEnum.adVarWChar, 1)
ADOXtable.Columns.Append("BITMAP", ADOX.DataTypeEnum.adInteger)
'append tables to database
cat.Tables.Append(ADOXtable)
ADOXtable.Name = "ACN_CHARX_INSTANCE"
ADOXtable.Columns.Append("LOGICAL_DB_NAME", ADOX.DataTypeEnum.adVarWChar, 32)
ADOXtable.Columns.Append("DIM_NAME", ADOX.DataTypeEnum.adVarWChar, 32)
ADOXtable.Columns.Append("CHARX_NAME", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("CHARX_TABLE", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("CHARX_VALUE_COL", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("VALUES_UNIQUE", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("CHARX_ORDER_COL", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("CHARX_ORDER", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("CHARX_NUMERIC_COL", ADOX.DataTypeEnum.adVarWChar, 128)
ADOXtable.Columns.Append("BITMAP_COL", ADOX.DataTypeEnum.adVarWChar, 128)
'append tables to database
cat.Tables.Append(ADOXtable)
Catch Excep As System.Runtime.InteropServices.COMException
bAns = False
MessageBox.Show(Excep.ToString)
Finally
cat = Nothing
End Try
Return bAns
End Function
Please help me to rectify this error...
Thanks,
Sivakumar.M.
modified on Wednesday, June 17, 2009 6:45 AM
|
|
|
|
|
Does the exception tell which line of code exactly is throwing the error?
My advice is free, and you may get what you paid for.
|
|
|
|
|
No...Actually the first table "ACN_CHARX" is created successfully... when it crosses the line "ADOXtable.Name = "ACN_CHARX_INSTANCE" ", the first created table name is automatically renamed.. ie)from "ACN_CHARX" into "ACN_CHARX_INSTANCE". Then the control tried to create the first column of the second table "Logical_db_name"...Then it shows this error....
|
|
|
|
|
I expect you need to add
ADOXtable = New ADOX.Table
between each table. Probably the same for the index.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Thanks for your nice solution....Now it is working fine....In addition with this, could you please mention how to add constraints with table columns through coding?
|
|
|
|
|
No problem, easy mistake to make, done it myself but usually realise when running in debug and stepping through the code
sivakumar.mariappan wrote: how to add constraints with table columns through coding?
No idea, I don't use access, but I bet google can help
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Hi,
I am new in Dotnet. I read the excel upto used ranges and print the data to messagebox. But I got Each value one by one after click the ok button.
But i need display the total data at once.
My Code is:
dim exapp as excel.application
dim exwork as excel.workbook
dim exsheet as excel.worksheet
exapp = New Excel.ApplicationClass
exwork = exapp.Workbooks.Open(TextBox1.Text)
exsheet = exwork.Worksheets("sheet1")
range = exsheet.UsedRange
For rcount = 1 To range.Rows.Count
For ccount = 1 To range.Columns.Count
obj = CType(range.Cells(rcount, ccount), Excel.Range)
MsgBox(obj.value)
Next
Next
exwork.Close()
exapp.Quit()
MsgBox("complete")
TextBox1.Clear()
Example: (In Excel)
No Name Age
1 Gopi 26
2 raja 24
3 mani 29
Output:
No,Name,Age
1,Gopi,26
2,raja,24
3,mani,29
But I got Each value one by one. I need full ouput as once. Please help me.
By
Gopi A
|
|
|
|
|
Well, you put a messagebox inside of a loop inside of another loop.
In other words, you are looping through all the cells in the sheet, and showing a messagebox for the value of each cell.
Try to concatenate the values in the cells into a string (for example) somehow, and then (for testing purposes) place MsgBox(MyConcatenatedString) outside the outer loop.
My advice is free, and you may get what you paid for.
|
|
|
|
|
try
dim st as string 'or to stringbuilder
dim exapp as excel.application
dim exwork as excel.workbook
dim exsheet as excel.worksheet
exapp = New Excel.ApplicationClass
exwork = exapp.Workbooks.Open(TextBox1.Text)
exsheet = exwork.Worksheets("sheet1")
range = exsheet.UsedRange
For rcount = 1 To range.Rows.Count
For ccount = 1 To range.Columns.Count
obj = CType(range.Cells(rcount, ccount), Excel.Range)
st = st + convert.tostring(obj)
Next
Next
MsgBox(st)
exwork.Close()
exapp.Quit()
MsgBox("complete")
TextBox1.Clear()
|
|
|
|
|
Anyhow I succeeded the SMTP-Emails. But as anext step, when they use my program, I want to send from their emails a/c. Rightnow I know only my network user Name & Paswword & My-email a/c name etc..
So how to detect their [network] system user name [I can find], Password, Email a/c ....?
Any better ideas for me? All my network Clients are using Windows XP
Thanks Again....
modified on Wednesday, June 17, 2009 3:47 AM
|
|
|
|
|
For obvious reasons it is not possible to just retrieve passwords to anything, through .net, think about it.
So unless you are intending to build a spam bot, you will simply have to offer the user the possibility to enter email address and password somewhere, and build a secure storage for that password, so hackers won't be able to abuse your program to collect passwords.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hello,
How can you change the size of the MDI container in a MDI parent form?
|
|
|
|
|