protected override void OnLoad(EventArgs e) { try { // The 'using' construct below results in a call to Dispose on exiting the // curly braces. It could be replaced with an explicit call to Object.Dispose // This is a C#-specific construct. // // It is important to dispose COM+ objects as soon as possible so that // COM+ metadata such as context does not remain in memory unnecessarily // and so that COM+ services such as Object Pooling work properly. using (TXDemoServer txDemoServer = new TXDemoServer()) //we want the object to be disposed immediately { // Retrieve & display the current value currentValue.Text = txDemoServer.RetrieveCurrentValue().ToString(CultureInfo.CurrentCulture); } } catch (CurrentValueNotReadException) { MessageBox.Show("Unable to read the current value from the database" , "Error"); Application.Exit(); } catch (Exception ex) { MessageBox.Show("An exception was caught : " + ex.Message + "\nUnable to launch the COM+ Server. Closing the application.", "Error"); Application.Exit(); } }
// Start the Post with a manual transaction if the user clicks on the // Post button private void Post_Click(object sender, System.EventArgs e) { int val = 0; try { val = int.Parse(newValue.Text, CultureInfo.CurrentCulture); } catch { MessageBox.Show("Please enter a value to post!"); return; } try { // The 'using' construct below results in a call to Dispose on exiting the // curly braces. It could be replaced with an explicit call to Object.Dispose // This is a C#-specific construct. // // It is important to dispose COM+ objects as soon as possible so that // COM+ metadata such as context does not remain in memory unnecessarily // and so that COM+ services such as Object Pooling work properly. using (TXDemoServer txDemoServer = new TXDemoServer()) //we want the object to be disposed immediately { txDemoServer.Post(val); } } catch (DatabaseExecutionException) { MessageBox.Show("Unable to update the database", "Error"); return; } catch (Exception ex) { MessageBox.Show("An exception was caught : " + ex.Message); return; } try { // The 'using' construct below results in a call to Dispose on exiting the // curly braces. It could be replaced with an explicit call to Object.Dispose // This is a C#-specific construct. // // It is important to dispose COM+ objects as soon as possible so that // COM+ metadata such as context does not remain in memory unnecessarily // and so that COM+ services such as Object Pooling work properly. using (TXDemoServer txDemoServer = new TXDemoServer()) //we want the object to be disposed immediately { currentValue.Text = txDemoServer.RetrieveCurrentValue().ToString(CultureInfo.CurrentCulture); } } catch (CurrentValueNotReadException) { MessageBox.Show("Unable to read the current value from the database", "Error"); return; } }