private bool ReadAux(string serverIP, int serverPort, string localFileName, SemanticType semantic, long minVersion) { IDataToClient dataServer = (IDataToClient)Activator.GetObject( typeof(IDataToClient), "tcp://" + serverIP + ":" + serverPort + "/PADIConnection"); AsyncReadDel RemoteDel = new AsyncReadDel(dataServer.Read); AsyncCallback RemoteCallback = new AsyncCallback(CBDoWhenReturnFromRead); try { IAsyncResult RemAr = RemoteDel.BeginInvoke(localFileName, RemoteCallback, null); } catch (Exception) { System.Console.WriteLine("#READ Could not locate server"); return(false); } return(true); }
public static void CBDoWhenReturnFromRead(IAsyncResult ar) { AsyncReadDel del = (AsyncReadDel)((AsyncResult)ar).AsyncDelegate; //Read TFile resp = del.EndInvoke(ar); // Pode Mandar Exepção System.Console.WriteLine("#READ *Data Server " + resp.responseServerId + " Returned from Read"); returnedReadIDs.Add(resp.responseServerId); returnedReadFiles.Add(resp); // Se somos o ultimo vamos informar a thread em espera no monitor if (returnedReadIDs.Count >= targetReadQuorum) { Thread.Yield(); Thread.Sleep(50); Thread.Yield(); System.Console.WriteLine("#READ *Last Data Server, Realeasing Main Thread"); Monitor.Enter(monReadLock); Monitor.Pulse(monReadLock); Monitor.Exit(monReadLock); } return; }