private static void Run() { NSAutoreleasePool pool = new NSAutoreleasePool (); Console.WriteLine ("Hello World !!!"); pool.Release (); }
// This event handler updates the progress bar. private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { NSAutoreleasePool pool = new NSAutoreleasePool(); this.progressIndicator.DoubleValue = e.ProgressPercentage; this.labelResult.StringValue = "Progress is " + e.ProgressPercentage + "%"; pool.Release(); }
/// <summary> /// Used for regression tests. /// </summary> public static void test_regression() { ObjectiveCRuntime.LoadFramework("Cocoa"); ObjectiveCRuntime.Initialize(); var test = new MonobjcTest(); test.OnBeginTest += () => { _pool = new NSAutoreleasePool(); }; test.OnEndTest += () => { _pool.Release(); _pool = null; }; test.TestAll(typeof(ObjectiveCRuntime).Assembly); }
private void DoComputation() { NSAutoreleasePool pool = new NSAutoreleasePool (); RayTracer rayTracer = new RayTracer (width, height, (int x, int y, NSColor color) => { this.imageRep.SetColorAtXy (color, x, y); if (x == 0) { this.imageView.PerformSelectorOnMainThreadWithObjectWaitUntilDone (ObjectiveCRuntime.Selector ("setNeedsDisplay"), null, false); } }); rayTracer.Render (rayTracer.DefaultScene); this.imageView.PerformSelectorOnMainThreadWithObjectWaitUntilDone (ObjectiveCRuntime.Selector ("setNeedsDisplay"), null, false); pool.Release (); }
public static Process[] GetProcesses() { // spin up the objective-c runtime ObjectiveCRuntime.LoadFramework("Cocoa"); ObjectiveCRuntime.Initialize(); NSAutoreleasePool pool = new NSAutoreleasePool(); // Create our process NSTask getPSTask = new NSTask(); NSPipe getPSStandardOut = new NSPipe(); getPSTask.StandardOutput = getPSStandardOut; getPSTask.LaunchPath = @"/bin/ps"; // add some arguments NSString getPSargumentString = new NSString("-ax"); NSArray getPSarguments = NSArray.ArrayWithObject(getPSargumentString); getPSTask.Arguments = getPSarguments; // We have liftoff getPSTask.Launch(); getPSTask.WaitUntilExit(); // Parse the output NSData getPSoutput = getPSStandardOut.FileHandleForReading.ReadDataToEndOfFile; NSString getPSoutString = new NSString(getPSoutput, NSStringEncoding.NSUTF8StringEncoding); // Split the string of output in to a list of processes string[] getPSsplitString = getPSoutString.ToString().Split(Environment.NewLine.ToCharArray()); // Remove the first and last line of the output string[] processListAsStrings = new string[getPSsplitString.Length - 2]; for (int x = 1; x < getPSsplitString.Length - 1; x++) { processListAsStrings[x - 1] = getPSsplitString[x]; } Process[] processes = new Process[processListAsStrings.Length]; for (int i = 0; i < processes.Length; i++) { string cleanString = RemoveExtraSpaces(processListAsStrings[i]); string[] processDetails = cleanString.Split(' '); Int32 procID = Convert.ToInt32(processDetails[0]); string procName = string.Empty; for (int j = 4; j < processDetails.Length; j++) { if (j == 4) { procName = procName + processDetails[j]; } else { procName = procName + " " + processDetails[j]; } } //Console.WriteLine(procID.ToString() + procName); processes[i] = new Process(procID, procName); } // Dipose our Objective-C objects, gotta love reference counting pool.Release(); return(processes); }
// This event handler deals with the results of the // background operation. private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { NSAutoreleasePool pool = new NSAutoreleasePool(); // First, handle the case where an exception was thrown. if (e.Error != null) { // TODO } else if (e.Cancelled) { this.labelResult.StringValue = "Canceled"; } else { this.labelResult.StringValue = "Fibonacci result for " + this.numberToCompute + " iterations is " + e.Result; } this.progressIndicator.DoubleValue = 0.0d; this.buttonStart.IsEnabled = true; this.buttonStop.IsEnabled = false; pool.Release(); }
private void ProcessRequests() { while (true) { // wait for an artwork request iPendingRequests.Wait(); // get the first request in the queue - leave the request in the queue for now so that if // the main thread requests it again, it will not get re-added and downloaded again string uri; ScalingUriConverter uriConverter; lock (iLock) { uri = iPendingRequests.FirstRequest; uriConverter = iUriConverter; } Trace.WriteLine(Trace.kKinskyDesktop, "ArtworkCache requesting " + uri); // download the image NSAutoreleasePool pool = new NSAutoreleasePool(); pool.Init(); NSImage image = null; try { string requestUri = uri; if (uriConverter != null) { requestUri = uriConverter.Convert(requestUri); } NSString s = NSString.StringWithUTF8String(Uri.UnescapeDataString(requestUri)); NSURL url = NSURL.URLWithString(s.StringByAddingPercentEscapesUsingEncoding(NSStringEncoding.NSUTF8StringEncoding)); image = new NSImage(url); } catch (Exception e) { UserLog.WriteLine("ArtworkCache.ProcessRequests: " + uri + " (" + e.Message + ")"); } pool.Release(); // insert the image into the cache List <Item> staleItems; lock (iLock) { // add to the cache Item item = new Item(uri, image); staleItems = iCacheData.Add(item); // remove the request iPendingRequests.Remove(uri); } // send notification that the image was added to the cache if (EventImageAdded != null) { EventImageAdded(this, new EventArgsArtwork(uri)); } // clean up all stale items outside of the lock foreach (Item item in staleItems) { if (item.Image != null) { item.Image.Release(); } } } }
public static void Run(String arg) { NSAutoreleasePool pool = new NSAutoreleasePool (); NSString CONNECTION_NAME = new NSString ("authentication test"); if (arg == "server") { // Create a generic NSConnection to use to vend an object over DO. NSConnection conn = new NSConnection (); // Create a generic object to vend over DO; usually this is an object // that actually has something interesting to do as a "server". NSObject @object = new NSObject (); // Create an Authenticator object to authenticate messages that come // in to the server. The client and server need to use the same // authentication logic, but would not need to use the same class. Authenticator authenticator = new Authenticator (); // Configure the connection conn.Delegate = authenticator; conn.RootObject = @object; // Set the name of the root object if (!conn.RegisterName (CONNECTION_NAME)) { Console.WriteLine ("OAuthenticator server: could not register server. Is one already running ?"); Environment.Exit (1); } Console.WriteLine ("OAuthenticator server: started"); // Have the run loop run forever, servicing incoming messages NSRunLoop.CurrentRunLoop.Run (); // Cleanup objects; not really necessary in this case authenticator.Release (); @object.Release (); conn.Release (); } else if (arg == "client") { // Create an Authenticator object to authenticate messages going // to the server. The client and server need to use the same // authentication logic, but would not need to use the same class. Authenticator authenticator = new Authenticator (); NSDistantObject proxy; // Lookup the server connection NSConnection conn = NSConnection.ConnectionWithRegisteredNameHost (CONNECTION_NAME, null); if (conn == null) { Console.WriteLine ("OAuthenticator client: could not find server. You need to start one on this machine first."); Environment.Exit (1); } // Set the authenticator as the NSConnection delegate; all // further messages, including the first one to lookup the root // proxy, will go through the authenticator. conn.Delegate = authenticator; proxy = conn.RootProxy; if (proxy == null) { Console.WriteLine ("OAuthenticator client: could not get proxy. This should not happen."); Environment.Exit (1); } // Since this is an example, we don't really care what the "served" // object really does, just that we can message it. Since it is just // an NSObject, send it some NSObject messages. If these aren't // authenticated successfully, an NSFailedAuthenticationException // exception is raised. Console.WriteLine ("description: {0}", proxy.Description); Console.WriteLine ("isKindOfClass NSObject ? {0}", proxy.IsKindOfClass (NSObject.NSObjectClass) ? "YES" : "NO"); Console.WriteLine ("Done. Messages sent successfully."); } else { Console.WriteLine ("Either server or client must be specified."); } pool.Release (); }
/// <summary> /// Converts the given value object to the specified type, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param> /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"/>. If null is passed, the current culture is assumed.</param> /// <param name="value">The <see cref="T:System.Object"/> to convert.</param> /// <param name="destinationType">The <see cref="T:System.Type"/> to convert the <paramref name="value"/> parameter to.</param> /// <returns> /// An <see cref="T:System.Object"/> that represents the converted value. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// The <paramref name="destinationType"/> parameter is null. /// </exception> /// <exception cref="T:System.NotSupportedException"> /// The conversion cannot be performed. /// </exception> public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { NSAutoreleasePool pool = null; try { // As pool are scoped, it does not hurt if we create ours during the method call. pool = new NSAutoreleasePool (); if (destinationType != typeof(byte[])) { return base.ConvertTo (context, culture, value, destinationType); } if (value == null) { return new byte[0]; } // The byte buffer returned will always be a TIFF representation for simplicity reasons. NSImage image = (NSImage)value; NSData data = image.TIFFRepresentation; return data.GetBuffer (); } finally { if (pool != null) { pool.Release (); } } }