|
Hi everybody,
I built and app that uses threads for a number of task, and at the end of every routine I call the Abort() method for its respective thread. While looking at the thread count indicator at the Task Manager, I noticed that this indicator always increases while the Output window indicates that the threads had successfully exited.
Is this normal or am I doing something very wrong?
Thanks great minds for your guidance.
Alex.
|
|
|
|
|
alexvw wrote: I call the Abort() method for its respective thread
As MSDN says about Thread.Abort(), The thread is not guaranteed to abort immediately, or at all. It's always good to exit the threads rather than calling Abort() . Please post your code so that we can come up with better suggestions.
|
|
|
|
|
//Declare thread var
Private Shared BkGrthread As Threading.Thread
//call sub that starts the thread
Private Sub Frm_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
...
InitThread(BkGrthread, 1)
...
End Sub
//Sub that starts the thread
Private Sub InitThread(ByRef Thread As Threading.Thread, ByRef ThreadIndex As Byte)
Try
Select Case ThreadIndex
Case 0 : Thread = New System.Threading.Thread(AddressOf ReceiveWkStat)
Case 1 : Thread = New System.Threading.Thread(AddressOf ReceiveTCPMsg)
Case 2 : Thread = New System.Threading.Thread(AddressOf ReceiveSys)
End Select
Thread.IsBackground = True
Thread.Priority = System.Threading.ThreadPriority.Normal
Thread.Start()
Catch
Msg(Err.Description, 16, "FrmMain::InitThread")
End Try
End Sub
//the following code was not created by me, I copied and modified it to fit my needs (so far it seems to work!)
Private Sub ReceiveTCPMsg()
Dim _data(1024) As Byte
Dim iMsg(), _Message As String
Dim TCPIP As Net.Sockets.TcpClient
Dim Stream As Net.Sockets.NetworkStream
Try
TCPIP = UDPManager.AcceptTcpClient
Stream = TCPIP.GetStream : Stream.Read(_data, 0, 1024)
TCPIP.GetStream.Close()
Stream = Nothing : TCPIP = Nothing
_Message = System.Text.Encoding.ASCII.GetString(_data)
iMsg = _Message.Split(",")
Select Case iMsg(1)
Case 1 : Invoke(sLoadNewEvent, New Object() {iMsg}) '**New Event Insertion
Case 2 : Invoke(sRemoveEvent, New Object() {iMsg}) '**Event Deletion
Case 3 : Invoke(sItemUpdate, New Object() {iMsg}) '**Event Item Update
Case 5 : Invoke(sTimeChange, New Object() {iMsg}) '**Update Event's Time
Case 6 : Invoke(sStatusChange, New Object() {iMsg}) '**Update Event's Status
Case 7 : Invoke(sTypeChange, New Object() {iMsg}) '**Update Event's Type
Case 11 : Invoke(sNewEventData, New Object() {iMsg}) '**Event Data
Case 12 : Invoke(sDeleteData, New Object() {iMsg}) '**Del Event Data
Case 13 : Invoke(sMaintenance, New Object() {iMsg}) '**system Maintenance
Case 15 : Load_IncrementValues()
Case 99 : UnconditionalEnd()
End Select
Catch
Msg(Err.Description & Chr(10) & _Message & Chr(10) & Err.GetException.StackTrace, 16, "MainMod::ReceiveTCPMsg")
Finally
InitThread(BkGrthread, 1)
End Try
BkGrthread.CurrentThread.Abort()
End Sub
This is all the code involved. I am using VS2002 Fmwrk 1.1. Most subs modify several controls on the main thread, therefore the use of Invoke.
Please, feel free to laugh or cry upon this code
Thanks for your time.
<div class="ForumMod">modified on Saturday, August 16, 2008 7:20 AM</div>
|
|
|
|
|
|
What you talking about Willis ?
I am guessing Excel somehow, but you don't make it remotely clear.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Hi
I have two locations referenced by
point1 = A5
point2 = A10
I need to use these variables in a calculation ie
=sum(point1:point2)
however this doesn't work?
when I use this statement
ActiveCell.Offset(0, 3).Value = "=sum(point1:point2)
any work around / solution?
if you require additional info let me know?
|
|
|
|
|
Please don't ask twice. Please try to use intelligent headers. EVeryone here wants help. Please make it clear what you're asking about. Visual Basic.NET does not have any control which references locations by A5 and A10, or has an ActiveCell, It seems likely you're talking about Excel, but VBScript or interop ? How are we to tell ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Matthew Leggett wrote: I have two locations referenced by
point1 = A5
point2 = A10
I need to use these variables in a calculation ie
=sum(point1:point2)
however this doesn't work?
when I use this statement
ActiveCell.Offset(0, 3).Value = "=sum(point1:point2)
any work around / solution?
if you require additional info let me know?
Try this:
ActiveCell.Offset(0, 3).Value = "=sum(" & Point1 & ":" & Point2 & ")"
This is of course assuming that you have Point1 and Point2 declared as strings.
|
|
|
|
|
Does anyone know how to shutoff/disable the automatic "feature" of changing the time of a date field when changing time zones? I want my dates to be left alone. I know I can change the field to type string but extra conversions would be necessary to compensate for changing the type. (this auto-feature happens when I am using a webservice)
Thanks,
Nathan
'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
|
|
|
|
|
You cannot remove the time component of the datetime type. You can however display any part of that component using format. You can also refuse to store the time value when writing it to the database (I do this everywhere EXCEPT where I explicitly need to time component) by using TODAY instead of NOW.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi, i am still a novice vb programmer.i want to know one thing.i want to write some code so that it will control objects outside my form.i mean generally we write code to work with the objects(say command button,list box etc.) that we place on our form.but how can i manipulate and take control of the objects outside my form.say,i want to write code so that a message box will be shown if a user double clicks on drive C: in my computer window.i think i need to take help of API.but i can't understand how to do it.anyone can help me out there? i am just freaking out.plz help me.
romance
romance
|
|
|
|
|
romance - see the one votes, they signify a stupid question, you have an inflated idea what you can do as a programmer specifically as a VB programmer. I imagine a very good developer (probably C++) with a deep knowledge of win32 api may be able to manage this but a newbie, not a chance.
Try something simple first, create an application that executes some business logic, retrieves and stores data, you know simple stuff. After you have spent a number of years gaining a well rounded knowledge of the programming tools available to you, think of this question and laugh at yourself.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i didn't mean to offend someone.yet you offended me.i think you don't know the answer of my question, nor do you have any knowledge of programming.
thanks and please don't disturb anyone by answering stupidly
romance
|
|
|
|
|
It's not that I don't know the answer to your question it's that your question does not make sense. It also indicates that you have no knowledge of the use and limitations of VB.
My response may have upset you but you will remember it, therefore I consider it a job well done. Get some understanding of the tools you propose to use, think about the projects you want to do, start working on the projects and when you run into a problem with coding, come back and we will help.
Note that no one responded to your question except to indicate it deserves a 1 vote.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi,
here i want to know, can i make a new variable, "Dim Variable as type" at the run time
when the my application load up it will create a new variable that can store a data.. is that possible? how can i make it?
|
|
|
|
|
shee_dee86 wrote: here i want to know, can i make a new variable, "Dim Variable as type" at the run time
when the my application load up it will create a new variable that can store a data.. is that possible? how can i make it?
Your question is not clear. Please try to explain what you wanna do.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
shee_dee86 wrote: "Dim Variable as type" at the run time
when the my application load up it will create a new variable that can store a data.. is that possible?
That is what it does
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Is it generating code at runtime? If yes then CodeDom or Reflection will help.
|
|
|
|
|
No, that is not possible.
Try to ask about what it is that you want to accomplish, instead of asking about how you think that it should be solved.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Last year, MikeinNH wrote an outstanding article on how to allow runtime SQL queries from form objects:
http://www.codeproject.com/KB/database/TableAdapter.aspx?display=Print
This almost all works for me except when I try to match database DateTime values. It doesn't act like any of the other variables and never finds a match. I don't think the problem is in SQL, I think it's in VB. My "Start Date Time" logic is below. Ideally, I'd like to use a between clause (eg. Between 'sdt' and 'edt') to make user records searchable in a time window that they choose.
Dim sdt As String = (sdtBox1.Text)
If sdt <> "" Then
stWhere = "DateTime > '" + sdt + "%' "
Else
The sdtBox1 value I'm testing with is '8/14/2008 00:00:00:001' and I can see that verbatim on a message box output, it just won't work in the SQL query. Is there a conversion or something that I need to do? Thanks
|
|
|
|
|
Just quickly looking at your code - it looks like the text date format is fine. What is the '%' for though? I think that would cause the query to error off. If you were using a LIKE statement maybe, but not a >.
Open up SQL profiler when your VB code runs and see the exact statement being sent into SQL. Paste that query in QA/ SQL Manager to see the results.
|
|
|
|
|
Right you are. I copied that from a LIKE statement.
When I removed the %, it still ignores my DateTime conditions, but I will check profiler to see what's happening.
Thanks.
|
|
|
|
|
Change "DateTime > '" + sdt + "%' "
to: " DateTime > '" + sdt + "%' " space added to the front. The where clause may have been all jumbled together.
|
|
|
|
|
Tried that, watched Profiler:
VB still didn't send that clause. It took my hardcoded front half ("Select From Where") plus the following AND condition successfully. But completely skipped DateTime.
I will keep playing with it, as long as it isn't an issue with text conversion or a DBDateTime property, then it's probably a syntax or logic error.
Thanks again for your help.
|
|
|
|
|
>>VB still didn't send that clause. It took my hardcoded front half ("Select From Where") plus the following AND condition successfully. But completely skipped DateTime.
Ok. it sounds like your doing everything right.
Last ditch effort: put a breakpoint on the FillByWhere function (assuming your following the article logic closely). Check the value on the WhereExp variable. What is the exact string after this line has run: "Me._commandCollection(0).CommandText += " WHERE " + WhereExp"?
That should be exactly what's being sent to the db. If the value is wrong there, press CTRL+L and go up the call stack to see where the value is being excluded.
Good luck~!
|
|
|
|