H Hirogens Active Member Licensed User Longtime User Jun 22, 2018 #1 Hello, I prefer to say it now: I will have a lot of questions I have just finish my project (I recreate DFU OTA) Now I would like to perform the code and try to avoid some problem. That's why I would like to know if an alternative to sleep exist. Because when I use the sleep function, I think some process continue to run, and I would like something which put everything in pause. thanks !
Hello, I prefer to say it now: I will have a lot of questions I have just finish my project (I recreate DFU OTA) Now I would like to perform the code and try to avoid some problem. That's why I would like to know if an alternative to sleep exist. Because when I use the sleep function, I think some process continue to run, and I would like something which put everything in pause. thanks !
Erel B4X founder Staff member Licensed User Longtime User Jun 22, 2018 #2 Not clear what you are using Sleep for and why you are looking for a replacement. Note that Sleep doesn't cause any thread to actually sleep. Upvote 0
Not clear what you are using Sleep for and why you are looking for a replacement. Note that Sleep doesn't cause any thread to actually sleep.
H Hirogens Active Member Licensed User Longtime User Jun 22, 2018 #3 Hum I use Sleep only to wait informations: for example I send a command to my device (Create objet), when the objet is create I receive information about this command (01 to success and other for an echec). I can't send information while I haven't my objet correctly create. So I use Sleep to wait this. It's work but not perfectly that's why I would like something to do nothing while I haven't receive the information. I don't know if I do something like this it can work Code: Copy boolean = false send_command_create While boolean = false{} When I have response from the device an event is reach and I can see if the command is success and then set this boolean to false Upvote 0
Hum I use Sleep only to wait informations: for example I send a command to my device (Create objet), when the objet is create I receive information about this command (01 to success and other for an echec). I can't send information while I haven't my objet correctly create. So I use Sleep to wait this. It's work but not perfectly that's why I would like something to do nothing while I haven't receive the information. I don't know if I do something like this it can work Code: Copy boolean = false send_command_create While boolean = false{} When I have response from the device an event is reach and I can see if the command is success and then set this boolean to false
LucaMs Expert Licensed User Longtime User Jun 22, 2018 #4 You should use resumable subs. https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/#content Upvote 0
You should use resumable subs. https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/#content
DonManfred Expert Licensed User Longtime User Jun 22, 2018 #5 Hirogens said: I don't know if I do something like this it can work Click to expand... I suggest to learn on how to use resumeable subs. https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/ Upvote 0
Hirogens said: I don't know if I do something like this it can work Click to expand... I suggest to learn on how to use resumeable subs. https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/
Semen Matusovskiy Well-Known Member Licensed User Jun 22, 2018 #6 It seems to me the question is not about Sleep / Wait For as it is. I would like something which put everything in pause Click to expand... It's enough typical situation, when an app sends a request to server and waits a reply. During waiting time user's activity is undesirable. Something similar modal Msgbox. Well, it's relatively simple to prevent user's activity (WindowManager.LayoutParams) and screen rotation (ActivityInfo). Upvote 0
It seems to me the question is not about Sleep / Wait For as it is. I would like something which put everything in pause Click to expand... It's enough typical situation, when an app sends a request to server and waits a reply. During waiting time user's activity is undesirable. Something similar modal Msgbox. Well, it's relatively simple to prevent user's activity (WindowManager.LayoutParams) and screen rotation (ActivityInfo).
KMatle Expert Licensed User Longtime User Jun 23, 2018 #7 Don't add complicated ways just for a wait. Mostly it's enough to disable some views and post a message like "Please wait". On the other hand a server's response takes some milliseconds so there isn't a problem at all. Upvote 0
Don't add complicated ways just for a wait. Mostly it's enough to disable some views and post a message like "Please wait". On the other hand a server's response takes some milliseconds so there isn't a problem at all.
Erel B4X founder Staff member Licensed User Longtime User Jun 24, 2018 #8 You should never try to hold the main thread. As written above you should learn how to use resumable subs. Upvote 0
You should never try to hold the main thread. As written above you should learn how to use resumable subs.
H Hirogens Active Member Licensed User Longtime User Jun 25, 2018 #9 Hello I don't know if resumable subs can help me: I send a command to my starter. Code: Copy CallSub(Starter, "recup_info_object") and this is the function in my starter Code: Copy Public Sub recup_info_object ManagerD.WriteData("0000fe59-0000-1000-8000-00805f9b34fb", "8ec90001-f315-4f60-9fb8-838830daea50", Array As Byte(0x06,0x01)) End Sub This command send to my device an instruction. When the device send to me the information that I ask this function Code: Copy Sub Manager_DataAvailable (Services As String, Characteristics As Map) CallSub3(Main, "DataAvailable", Services, Characteristics) End Sub handle the response, and in my main I treate the informations. If my command is a success I can continue the code. I have a lot of command like this and that's why I need to be sure to handle the response everytime. I don't know if it can help you more :/ Maybe you're right with resumable subs but maybe there is an other option =) Thanks ! Upvote 0
Hello I don't know if resumable subs can help me: I send a command to my starter. Code: Copy CallSub(Starter, "recup_info_object") and this is the function in my starter Code: Copy Public Sub recup_info_object ManagerD.WriteData("0000fe59-0000-1000-8000-00805f9b34fb", "8ec90001-f315-4f60-9fb8-838830daea50", Array As Byte(0x06,0x01)) End Sub This command send to my device an instruction. When the device send to me the information that I ask this function Code: Copy Sub Manager_DataAvailable (Services As String, Characteristics As Map) CallSub3(Main, "DataAvailable", Services, Characteristics) End Sub handle the response, and in my main I treate the informations. If my command is a success I can continue the code. I have a lot of command like this and that's why I need to be sure to handle the response everytime. I don't know if it can help you more :/ Maybe you're right with resumable subs but maybe there is an other option =) Thanks !
Erel B4X founder Staff member Licensed User Longtime User Jun 25, 2018 #10 Valid code: Code: Copy Ready = False 'global variable send_command_create Do While Ready = False Sleep(100) Loop Please don't ask questions about the code flow unless you watched and understood the resumable subs video. Upvote 0
Valid code: Code: Copy Ready = False 'global variable send_command_create Do While Ready = False Sleep(100) Loop Please don't ask questions about the code flow unless you watched and understood the resumable subs video.