Skip to content

Commit 2dc2d9e

Browse files
committed
Updated Sub Thread
1 parent b8e2f64 commit 2dc2d9e

35 files changed

+329
-134
lines changed
4 KB
Binary file not shown.

ScreenSharing_Desktop/Releases/RELEASES

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
8F7D16DB141E09AE923215383304D241133344CB ScreenSharingApp-2.0.2-delta.nupkg 13868
33
6ACCBF93CC20700AFBC3CF8489DE434C5ADD1B42 ScreenSharingApp-2.0.2-full.nupkg 1414970
44
7F4FB6C1C4392C6F5A709B6650A9C6E1A52E0D80 ScreenSharingApp-2.0.3-delta.nupkg 13761
5-
B002214063ABD26B49C7307C4596F7AFFA302A33 ScreenSharingApp-2.0.3-full.nupkg 1415091
5+
B002214063ABD26B49C7307C4596F7AFFA302A33 ScreenSharingApp-2.0.3-full.nupkg 1415091
6+
33F7C96E27C68780D4BC63CAACD5693E34A1FCDD ScreenSharingApp-2.0.4-delta.nupkg 14311
7+
A84A8199EF1F26AC8A69F3963AC222F461125285 ScreenSharingApp-2.0.4-full.nupkg 1415346
8+
8788A6D2313B6B337A5B0E8BEC538EADC7CA7359 ScreenSharingApp-2.0.5-delta.nupkg 13425
9+
BD62ABA27CC7567E5FB8F8C98F590B556D29E9B5 ScreenSharingApp-2.0.5-full.nupkg 1415365
10+
9087E3CC5390B7F5D331B157275B5B860658533D ScreenSharingApp-2.0.6-delta.nupkg 13633
11+
4B591F2E3D3F2815CDAC70D31740A4915F8A4AF5 ScreenSharingApp-2.0.6-full.nupkg 1415383
-13.4 KB
Binary file not shown.

ScreenSharing_Desktop/Releases/ScreenSharingApp-2.0.2-full.nupkg renamed to ScreenSharing_Desktop/Releases/ScreenSharingApp-2.0.5-full.nupkg

1.35 MB
Binary file not shown.
Binary file not shown.

ScreenSharing_Desktop/Releases/ScreenSharingApp-2.0.3-full.nupkg renamed to ScreenSharing_Desktop/Releases/ScreenSharingApp-2.0.6-full.nupkg

1.35 MB
Binary file not shown.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1.74 MB
Binary file not shown.

ScreenSharing_Desktop/ScreenSharing_Desktop/CoreClasses/Main.cs

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,29 @@ public static CommunicationTypes CommunicationType
144144
private static object Lck_Ping = new object();
145145

146146
private static Thread SenderThread;
147+
private static Thread ReceiverThread;
147148

149+
private static bool IsReceiverThreadEnabled = false;
150+
private static bool IsSubDataReceived
151+
{
152+
get
153+
{
154+
lock (Lck_IsSubDataReceived)
155+
return _isSubDataReceived;
156+
}
157+
set
158+
{
159+
lock (Lck_IsSubDataReceived)
160+
_isSubDataReceived = value;
161+
}
162+
}
163+
164+
private static byte[] SubReceivedData;
165+
166+
private static bool _isSubDataReceived = false;
167+
168+
private static object Lck_SubReceivedData = new object();
169+
private static object Lck_IsSubDataReceived = new object();
148170
#endregion
149171

150172
#region MQ Variables
@@ -168,6 +190,7 @@ public static CommunicationTypes CommunicationType
168190

169191
private static TimeSpan PublisherTimeBase;
170192
private static TimeSpan SubscriberPreviousTime;
193+
private static int ScanCounter = 0;
171194

172195
public enum CommunicationTypes
173196
{
@@ -252,8 +275,57 @@ public static void StartReceiving(string ip)
252275
TimeBaseSubscriber.OnDataReceived += TimeBaseSubscriber_OnDataReceived;
253276
SubStopwatch = Stopwatch.StartNew();
254277
CommunicationType = CommunicationTypes.Receiver;
278+
IsReceiverThreadEnabled = true;
279+
ReceiverThread = new Thread(ReceiverCoreFcn);
280+
ReceiverThread.Start();
255281
}
282+
private static void ReceiverCoreFcn()
283+
{
284+
while(IsReceiverThreadEnabled)
285+
{
286+
if (IsSubDataReceived)
287+
{
288+
IsSubDataReceived = false;
289+
Stopwatch stp = Stopwatch.StartNew();
290+
byte[] timeBytes = new byte[16];
291+
byte[] receivedData;
292+
lock(Lck_SubReceivedData)
293+
{
294+
receivedData = new byte[SubReceivedData.Length];
295+
SubReceivedData.CopyTo(receivedData, 0);
296+
}
256297

298+
Array.Copy(receivedData, 0, timeBytes, 0, timeBytes.Length);
299+
string timeString = Encoding.ASCII.GetString(timeBytes);
300+
TimeSpan SentTime = TimeSpan.Parse(timeString);
301+
TimeSpan CurrentTime = DateTime.UtcNow.TimeOfDay;
302+
PublisherTimeBase += (CurrentTime - SubscriberPreviousTime);
303+
SubscriberPreviousTime = CurrentTime;
304+
double deltaTime = PublisherTimeBase.TotalMilliseconds - SentTime.TotalMilliseconds;
305+
if (Ping <= 0)
306+
Ping = deltaTime;
307+
Ping = Ping * 0.99 + 0.01 * deltaTime;
308+
byte[] ScreenBytes = new byte[receivedData.Length - timeBytes.Length];
309+
Array.Copy(receivedData, timeBytes.Length, ScreenBytes, 0, ScreenBytes.Length);
310+
ScreenImage = ImageProcessing.ImageFromByteArray(ScreenBytes);
311+
TotalBytesReceived += receivedData.Length;
312+
FpsCounter++;
313+
if (SubStopwatch.ElapsedMilliseconds >= 1000)
314+
{
315+
UpdateStats(TotalBytesReceived, SubStopwatch.Elapsed.TotalSeconds);
316+
TotalBytesReceived = 0;
317+
SubStopwatch.Restart();
318+
}
319+
IsImageShowed = true;
320+
}
321+
else
322+
{
323+
ScanCounter++;
324+
325+
Thread.Sleep(1);
326+
}
327+
}
328+
}
257329
private static void TimeBaseSubscriber_OnDataReceived(byte[] data)
258330
{
259331
if (data != null)
@@ -265,32 +337,18 @@ private static void TimeBaseSubscriber_OnDataReceived(byte[] data)
265337

266338
private static void Subscriber_OnDataReceived(byte[] data)
267339
{
268-
Stopwatch stp = Stopwatch.StartNew();
269340
if (data != null)
270341
{
271-
byte[] timeBytes = new byte[16];
272-
Array.Copy(data, 0, timeBytes, 0, timeBytes.Length);
273-
string timeString = Encoding.ASCII.GetString(timeBytes);
274-
TimeSpan SentTime = TimeSpan.Parse(timeString);
275-
TimeSpan CurrentTime = DateTime.UtcNow.TimeOfDay;
276-
PublisherTimeBase += (CurrentTime - SubscriberPreviousTime);
277-
SubscriberPreviousTime = CurrentTime;
278-
double deltaTime = PublisherTimeBase.TotalMilliseconds - SentTime.TotalMilliseconds;
279-
if (Ping <= 0)
280-
Ping = deltaTime;
281-
Ping = Ping * 0.99 + 0.01 * deltaTime;
282-
byte[] ScreenBytes = new byte[data.Length - timeBytes.Length];
283-
Array.Copy(data, timeBytes.Length, ScreenBytes, 0, ScreenBytes.Length);
284-
ScreenImage = ImageProcessing.ImageFromByteArray(ScreenBytes);
285-
TotalBytesReceived += data.Length;
286-
FpsCounter++;
287-
if (SubStopwatch.ElapsedMilliseconds >= 1000)
342+
lock (Lck_SubReceivedData)
343+
{
344+
SubReceivedData = data;
345+
}
346+
IsSubDataReceived = true;
347+
if (ScanCounter > 250)
288348
{
289-
UpdateStats(TotalBytesReceived, SubStopwatch.Elapsed.TotalSeconds);
290-
TotalBytesReceived = 0;
291-
SubStopwatch.Restart();
349+
NetworkScanner.ScanAvailableDevices();
350+
ScanCounter = 0;
292351
}
293-
IsImageShowed = true;
294352
}
295353
else
296354
{
@@ -301,6 +359,7 @@ public static void StopReceiving()
301359
{
302360
Subscriber.Stop();
303361
TimeBaseSubscriber.Stop();
362+
IsReceiverThreadEnabled = false;
304363
FPS = 0;
305364
TransferSpeed = 0;
306365
}

0 commit comments

Comments
 (0)