Good. You need to keep that error trapping in place.Yes this code works without an errors,
That cannot be anything to do with the threading library. More likely it is something in your device IP stack that causes the initial delay. Try increasing your HTTP timeout.but it works from the second-third time... When i press the button for the first time, there is always "no response received" inscription...
No question is a stupid question if the asker really doesn't know the answer to it :sign0098:my stupid questions
I don't know!- what's wrong here ?
Yes, there should be no problem unless you also call that Sub from the main program or another thread. Keep thread code strictly segregated from other code.Can i call a sub from a sub which has been started as a thread or not ?
No. Please read carefully the Thread Pitfalls page of the help. Especially the GUI operations section.if it's ok to call a sub from a threaded sub, can the called sub access the controls of the main gui program ?
Use FireThreadEvent or FireDebugEvent to "call" your subs that manipulate GUI controls. They are provided as a safe path to the the GUI thread. You can only safely manipulate GUI controls in the main thread or in these events or Subs called by them. If you need multiple different operations then distinguish them in the event by setting a Global variable in the thread and doing a Select.... Case in the event.if not, how can i work around this ?
Unsafe means don't do it because bad things can happen!would be unsafe to manipulate GUI elements, not it would be impossible.
They are not errors. This is explained this in the the "Thread debugging" section of the help. Please re-read it. As the first line says "Threads may only be used in optimised compiled Basic4PPC applications". That section of help documents the differences between optimised and legacy operations and the demo app shows how to ameliorate some of those differences.What is the reason for these errors ? Has the desktop lib/version only limited functionality ? Is it possible to suppress these error messages..?
sub serverB_click
waitforconnection.Enabled = True
server.New1(50000) 'Listens on port 50000 (all ip's available).
server.Start
End Sub
Sub WaitForConnection_Tick
If server.Pending = True Then
client.Value = server.Accept
remote_on_flag = 1 ' communication established
WaitForconnection.Enabled = False ' this is where I have to stop the timer
WaitForData.Enabled = True
End If
End sub
Sub WaitForConnection_Tick
If Not(Thread.Start("Main.accept")) Then accept
If accepted = 1 Then
remote_on_flag = 1 ' communication established
'WaitForconnection.Enabled = False
WaitForData.Enabled = True
accepted = 0
End If
End Sub
Public Sub accept
If server.Pending = True Then
client.Value = server.Accept
accepted = 1
End If
End Sub
Sub WaitForConnection_Tick
If Not(Thread.Start("Main.accept")) Then accept
That's what RunLockedx is for. Stick the accesses you need protected in a Sub and run it by calling the appropriate RunLockedx method from both your thread and your main code. A Sub run by RunLockedx is run as a critical section that can only be entered by one thread at a time. The call blocks until the synchronisation object is free. It uses the C# "lock" construct. If you look at the source it's like this (almost!)i cant see anything to create a criticalsection around shared variables etc.
public string RunLocked0(string sub)
{
// minimise locked time by looking up the Sub delegate first
b4p.del0 del = (b4p.del0)htSubs[b4pname(sub)];
lock (this) // use the Basic4ppc Thread object for synchronisation
{
return del(); // del is the delegate that invokes the Sub
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?