Posts

File shared C# code

 FileStream stream = File.OpenRead(filePath); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Close(); ======================= NetworkStream stream = client.GetStream();                     if (flag == 1 && isConnected)                     {                         savePath = savePathLabel.Text + "\\" + fileName;                         using (var output = File.Create(savePath))                         {                             // read the file divided by 1KB                             var buffer = new byte[1024]; ...

Practice Question PDC

  If you do NOT want a thread to be blocked, you can use Monitor.TryEnter(buffer), which • acquires the lock and returns true, if the lock is available; • returns false, if the lock is not available. • The thread can execute other code, instead of simply being blocked using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading;   namespace PlusAndWait {     class Program     {         static int count = 0;         bool isfree= true ;         public void Sum()         {             /*if (isfree)             {           ...