C# Screen-Share Project

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-1
down vote
favorite
I've recently been working on a screen-sharing/remote desktop project in C# .NET Framework 4.5. How it works is when the start button is pressed, the client will send a command to the server to begin sending screenshots until the screen-sharing bool is false (i.e the 'Stop' button is pressed).
All data is prefixed with a byte identifying what command it is, and the following 4 bytes are used to measure the length of the packet.
My question is, should I be using a Thread or a Task for this job? I need one or the other, otherwise the client's UI freezes.
Below I am using a Thread:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
new Thread(StartSharing).Start();
private void StartSharing()
Globals.screensharing = true;
while (Globals.screensharing)
Methods.SendCapture();
And over here is how it looks with a Task:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
Task.Run(() =>
while (Globals.screensharing)
Methods.SendCapture();
);
I'm unsure what would be the better option here.
c#
add a comment |Â
up vote
-1
down vote
favorite
I've recently been working on a screen-sharing/remote desktop project in C# .NET Framework 4.5. How it works is when the start button is pressed, the client will send a command to the server to begin sending screenshots until the screen-sharing bool is false (i.e the 'Stop' button is pressed).
All data is prefixed with a byte identifying what command it is, and the following 4 bytes are used to measure the length of the packet.
My question is, should I be using a Thread or a Task for this job? I need one or the other, otherwise the client's UI freezes.
Below I am using a Thread:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
new Thread(StartSharing).Start();
private void StartSharing()
Globals.screensharing = true;
while (Globals.screensharing)
Methods.SendCapture();
And over here is how it looks with a Task:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
Task.Run(() =>
while (Globals.screensharing)
Methods.SendCapture();
);
I'm unsure what would be the better option here.
c#
You're missing theGlobals.screensharing = true;assignment in the Pool version.
â 1201ProgramAlarm
Feb 11 at 1:01
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I've recently been working on a screen-sharing/remote desktop project in C# .NET Framework 4.5. How it works is when the start button is pressed, the client will send a command to the server to begin sending screenshots until the screen-sharing bool is false (i.e the 'Stop' button is pressed).
All data is prefixed with a byte identifying what command it is, and the following 4 bytes are used to measure the length of the packet.
My question is, should I be using a Thread or a Task for this job? I need one or the other, otherwise the client's UI freezes.
Below I am using a Thread:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
new Thread(StartSharing).Start();
private void StartSharing()
Globals.screensharing = true;
while (Globals.screensharing)
Methods.SendCapture();
And over here is how it looks with a Task:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
Task.Run(() =>
while (Globals.screensharing)
Methods.SendCapture();
);
I'm unsure what would be the better option here.
c#
I've recently been working on a screen-sharing/remote desktop project in C# .NET Framework 4.5. How it works is when the start button is pressed, the client will send a command to the server to begin sending screenshots until the screen-sharing bool is false (i.e the 'Stop' button is pressed).
All data is prefixed with a byte identifying what command it is, and the following 4 bytes are used to measure the length of the packet.
My question is, should I be using a Thread or a Task for this job? I need one or the other, otherwise the client's UI freezes.
Below I am using a Thread:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
new Thread(StartSharing).Start();
private void StartSharing()
Globals.screensharing = true;
while (Globals.screensharing)
Methods.SendCapture();
And over here is how it looks with a Task:
private void ProcessCommand(byte command)
if (command == Commands.StartRemoteDesktop && !Globals.screensharing)
Task.Run(() =>
while (Globals.screensharing)
Methods.SendCapture();
);
I'm unsure what would be the better option here.
c#
edited Feb 10 at 20:41
Jamalâ¦
30.1k11114225
30.1k11114225
asked Feb 10 at 20:31
lol
1365
1365
You're missing theGlobals.screensharing = true;assignment in the Pool version.
â 1201ProgramAlarm
Feb 11 at 1:01
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25
add a comment |Â
You're missing theGlobals.screensharing = true;assignment in the Pool version.
â 1201ProgramAlarm
Feb 11 at 1:01
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25
You're missing the
Globals.screensharing = true; assignment in the Pool version.â 1201ProgramAlarm
Feb 11 at 1:01
You're missing the
Globals.screensharing = true; assignment in the Pool version.â 1201ProgramAlarm
Feb 11 at 1:01
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
It depends on what you mean by "better". I'd use a Thread since the job is constantly running.
A Thread object will be a foreground thread, which will prevent the application from terminating as long as it is running.
Task.Run will queue the job up to run on a thread pool thread. It may not start running immediately, and it will be a background thread, so it will not prevent the application from terminating if all other foreground threads have terminated.
The number of threads that a thread pool can run is limited, so if your job is always using one of them that increases the possibility that some other task will run late. Or possibly your job will be delayed while some other task that is part of the thread pool runs.
Mhmm... but you can also make the tastLongRunning...
â t3chb0t
Feb 11 at 8:27
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It depends on what you mean by "better". I'd use a Thread since the job is constantly running.
A Thread object will be a foreground thread, which will prevent the application from terminating as long as it is running.
Task.Run will queue the job up to run on a thread pool thread. It may not start running immediately, and it will be a background thread, so it will not prevent the application from terminating if all other foreground threads have terminated.
The number of threads that a thread pool can run is limited, so if your job is always using one of them that increases the possibility that some other task will run late. Or possibly your job will be delayed while some other task that is part of the thread pool runs.
Mhmm... but you can also make the tastLongRunning...
â t3chb0t
Feb 11 at 8:27
add a comment |Â
up vote
0
down vote
It depends on what you mean by "better". I'd use a Thread since the job is constantly running.
A Thread object will be a foreground thread, which will prevent the application from terminating as long as it is running.
Task.Run will queue the job up to run on a thread pool thread. It may not start running immediately, and it will be a background thread, so it will not prevent the application from terminating if all other foreground threads have terminated.
The number of threads that a thread pool can run is limited, so if your job is always using one of them that increases the possibility that some other task will run late. Or possibly your job will be delayed while some other task that is part of the thread pool runs.
Mhmm... but you can also make the tastLongRunning...
â t3chb0t
Feb 11 at 8:27
add a comment |Â
up vote
0
down vote
up vote
0
down vote
It depends on what you mean by "better". I'd use a Thread since the job is constantly running.
A Thread object will be a foreground thread, which will prevent the application from terminating as long as it is running.
Task.Run will queue the job up to run on a thread pool thread. It may not start running immediately, and it will be a background thread, so it will not prevent the application from terminating if all other foreground threads have terminated.
The number of threads that a thread pool can run is limited, so if your job is always using one of them that increases the possibility that some other task will run late. Or possibly your job will be delayed while some other task that is part of the thread pool runs.
It depends on what you mean by "better". I'd use a Thread since the job is constantly running.
A Thread object will be a foreground thread, which will prevent the application from terminating as long as it is running.
Task.Run will queue the job up to run on a thread pool thread. It may not start running immediately, and it will be a background thread, so it will not prevent the application from terminating if all other foreground threads have terminated.
The number of threads that a thread pool can run is limited, so if your job is always using one of them that increases the possibility that some other task will run late. Or possibly your job will be delayed while some other task that is part of the thread pool runs.
answered Feb 11 at 1:01
1201ProgramAlarm
2,5302618
2,5302618
Mhmm... but you can also make the tastLongRunning...
â t3chb0t
Feb 11 at 8:27
add a comment |Â
Mhmm... but you can also make the tastLongRunning...
â t3chb0t
Feb 11 at 8:27
Mhmm... but you can also make the tast
LongRunning...â t3chb0t
Feb 11 at 8:27
Mhmm... but you can also make the tast
LongRunning...â t3chb0t
Feb 11 at 8:27
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187278%2fc-screen-share-project%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
You're missing the
Globals.screensharing = true;assignment in the Pool version.â 1201ProgramAlarm
Feb 11 at 1:01
Have you tested both versions?
â t3chb0t
Feb 11 at 8:25