Click here to Skip to main content
15,912,665 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: I created org chart using trial version, it is running only in localhost. If i want to run IIS it is giving message like u have to purchase and i am not able to view that chart. Is there any alternation solution to view that chart and run in Serv Pin
Pete O'Hanlon9-Sep-10 1:38
mvePete O'Hanlon9-Sep-10 1:38 
AnswerRe: I created org chart using trial version, it is running only in localhost. If i want to run IIS it is giving message like u have to purchase and i am not able to view that chart. Is there any alternation solution to view that chart and run in Serv Pin
Dave Kreskowiak9-Sep-10 3:51
mveDave Kreskowiak9-Sep-10 3:51 
GeneralRe: I created org chart using trial version, it is running only in localhost. If i want to run IIS it is giving message like u have to purchase and i am not able to view that chart. Is there any alternation solution to view that chart and run in Serv Pin
fjdiewornncalwe9-Sep-10 7:29
professionalfjdiewornncalwe9-Sep-10 7:29 
GeneralRe: I created org chart using trial version, it is running only in localhost... Pin
Kunal Chowdhury «IN»10-Sep-10 17:12
professionalKunal Chowdhury «IN»10-Sep-10 17:12 
QuestionOdd problem with UDPClient [modified] - Solved Pin
Peter R. Fletcher8-Sep-10 9:17
Peter R. Fletcher8-Sep-10 9:17 
AnswerRe: Odd problem with UDPClient Pin
Luc Pattyn8-Sep-10 9:32
sitebuilderLuc Pattyn8-Sep-10 9:32 
GeneralRe: Odd problem with UDPClient Pin
Peter R. Fletcher8-Sep-10 10:20
Peter R. Fletcher8-Sep-10 10:20 
GeneralRe: Odd problem with UDPClient Pin
Luc Pattyn8-Sep-10 10:53
sitebuilderLuc Pattyn8-Sep-10 10:53 
OK, here are some thoughts:

1.
I'm inclined to use less code; so I'll try and get rid of some. Simpler is better, assuming it works.

2.
I would replace your current Sub ReceiveMessage() by something along these lines:
Private Sub ReceiveMessages()
        Try
            ThreadReceive = New System.Threading.Thread(AddressOf ReceiverMethod)
            ThreadReceive.Start()
        Catch ex As System.Threading.ThreadAbortException
            ' this generally means that the thread was deliberately aborted, so we can ignore it
        Catch e As Exception
            If Not ShuttingDown Then Throw New ApplicationException("Problem receiving data from Thermostat" & vbCrLf, e)
        End Try
End Sub

Private Sub ReceiverMethod()
    While Not ShuttingDown
        Try   
            Dim receiveBytes As [Byte]() = TCudpClient.Receive(RecEndpoint)
        ' Some error checking code omitted
            Process_Heartbeat(receiveBytes)

            If NewSettings Then ' There are some queued commands
                UpDating = True ' Set a flag to prevent new commands being added while we are processing existing ones
                Send_Commands() ' See below
                UpDating = False
                NewSettings = False
            End If
        Catch ex As System.Threading.ThreadAbortException
            ' this generally means that the thread was deliberately aborted, so we can ignore it
        Catch e As Exception
            If Not ShuttingDown Then Throw New ApplicationException("Problem receiving data from Thermostat" & vbCrLf, e)
        End Try
    End While
End Sub


This makes sure only one extra thread is used, and every execution of the original code is by that one thread (including the very first, which wasn't true at all in the original code). The original with a new thread every so often is expensive on system resources, and has the risk of two of those threads running at the same time, confusing you and making you add code to fix things that could have been avoided.

Note: some details may need fixing (e.g. what exceptions to catch, and how to deal with them)

[ADDED]
Remark: make sure the while loop is blocking somehow; it should not just sit there spinning like mad, wasting lots of CPU cycles; if there is no way to make it block (i.e. wait on something), insert a time delay using Thread.Sleep
[/ADDED]

3.
Just remove the DoEvent stuff.

4.
If you want to send the same thing twice, no need to have two for loops. This should do:
For Each tc In ThermostatCommands ' find the first available command
   If tc.Pending Then
        System.Threading.Thread.Sleep(100)
        SendMessage(tc.ComBuff) ' See below
         System.Threading.Thread.Sleep(100)
        SendMessage(tc.ComBuff) ' See below
        tc.ComBuff = Nothing
        tc.Pending = False
        Exit For
    End If
Next


5.
Not sure what ThermostatCommands is, and why you need a pending flag and why you clear the ComBuff; I would be inclined to create new command objects and stuff them in a Queue. Then the sender does not need a for loop at all, it just pulls the head of the queue and sends it.

6.
I'm pretty sure debugging such application is mind boggling if you create a lot of threads, then try to single-step and watch in some IDE or debugger. I tackle those apps differently, by adding logging code,
making sure each log line gets a time stamp. This article[^] gives the philosophy and some code snippets (in C#, could be done in VB.NET equally well).

7.
After some refactoring along above lines, I would not be surprised if some of your comments became obsolete, I mean the ones about the first message sometimes failing, and possibly also about having to send things twice.


Good luck.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.


GeneralRe: Odd problem with UDPClient Pin
Peter R. Fletcher9-Sep-10 10:44
Peter R. Fletcher9-Sep-10 10:44 
GeneralRe: Odd problem with UDPClient Pin
Luc Pattyn9-Sep-10 10:59
sitebuilderLuc Pattyn9-Sep-10 10:59 
GeneralRe: Odd problem with UDPClient Pin
Peter R. Fletcher13-Sep-10 4:51
Peter R. Fletcher13-Sep-10 4:51 
QuestionAdding different contorl( combox, textbox) in a single coloumn of datagirdview (window) Pin
shahabsuhail7-Sep-10 22:56
shahabsuhail7-Sep-10 22:56 
AnswerRe: Adding different contorl( combox, textbox) in a single coloumn of datagirdview (window) Pin
Dave Kreskowiak8-Sep-10 4:18
mveDave Kreskowiak8-Sep-10 4:18 
Questionapplication path Pin
Jefry boycot7-Sep-10 4:59
Jefry boycot7-Sep-10 4:59 
AnswerRe: application path Pin
The Man from U.N.C.L.E.7-Sep-10 6:34
The Man from U.N.C.L.E.7-Sep-10 6:34 
AnswerRe: application path Pin
RaviRanjanKr15-Dec-10 5:25
professionalRaviRanjanKr15-Dec-10 5:25 
QuestionHow does Application.DoEvents work? Pin
MicroVirus7-Sep-10 2:44
MicroVirus7-Sep-10 2:44 
AnswerRe: How does Application.DoEvents work? Pin
Luc Pattyn7-Sep-10 3:17
sitebuilderLuc Pattyn7-Sep-10 3:17 
GeneralRe: How does Application.DoEvents work? Pin
MicroVirus7-Sep-10 9:25
MicroVirus7-Sep-10 9:25 
AnswerRe: How does Application.DoEvents work? Pin
Johann Gerell8-Sep-10 2:41
Johann Gerell8-Sep-10 2:41 
GeneralRe: How does Application.DoEvents work? Pin
Luc Pattyn8-Sep-10 2:45
sitebuilderLuc Pattyn8-Sep-10 2:45 
GeneralRe: How does Application.DoEvents work? Pin
Spectre_0018-Sep-10 4:18
Spectre_0018-Sep-10 4:18 
GeneralRe: How does Application.DoEvents work? Pin
Luc Pattyn8-Sep-10 4:30
sitebuilderLuc Pattyn8-Sep-10 4:30 
AnswerRe: How does Application.DoEvents work? Pin
Guy Harwood8-Sep-10 2:05
Guy Harwood8-Sep-10 2:05 
GeneralRe: How does Application.DoEvents work? Pin
Mike Devenney8-Sep-10 2:49
Mike Devenney8-Sep-10 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.