本文整理汇总了C#中this.Close方法的典型用法代码示例。如果您正苦于以下问题:C# this.Close方法的具体用法?C# this.Close怎么用?C# this.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteProcWithParamsDT
/// <summary>
/// Execute Stored Procedure with the Parameters passed
/// </summary>
/// <param name="Conn"></param>
/// <param name="procname"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static DataTable ExecuteProcWithParamsDT(this SqlConnection Conn, string procname, Hashtable parameters)
{
DataSet dataSet;
try
{
SqlDataAdapter dataAdaptor = new SqlDataAdapter();
dataAdaptor.SelectCommand = new SqlCommand(procname, Conn);
dataAdaptor.SelectCommand.CommandType = CommandType.StoredProcedure;
if (parameters != null)
foreach (DictionaryEntry de in parameters)
{
SqlParameter sp = new SqlParameter(de.Key.ToString(), de.Value.ToString());
dataAdaptor.SelectCommand.Parameters.Add(sp);
}
dataSet = new DataSet();
dataAdaptor.Fill(dataSet, "table");
Conn.Close();
return dataSet.Tables["table"];
}
catch (Exception ex)
{
dataSet = null;
Conn.Close();
return null;
}
finally
{
Conn.Close();
dataSet = null;
}
}
示例2: Dispose
public static void Dispose(this ICommunicationObject communicationObject, TimeSpan? closeTimeout)
{
bool abort = true;
try
{
if (closeTimeout.HasValue)
{
communicationObject.Close(closeTimeout.Value);
}
else
{
communicationObject.Close();
}
abort = false;
}
catch (Exception e) when (e is TimeoutException || e is CommunicationException)
{
}
finally
{
if (abort)
{
Trace.TraceWarning($"{nameof(CommunicationObjectExtensionMethods)}.{nameof(Dispose)}: The communication object is being aborted.");
communicationObject.Abort();
}
}
}
示例3: CloseIfNotNull
public static void CloseIfNotNull(this ICloseable closable)
{
if (closable != null) {
if (closable is Component) {
if ((Component)closable) {
closable.Close();
}
} else {
closable.Close();
}
}
}
示例4: CloseDoc
///<summary>Forces a document to close.</summary>
///<remarks>This method works around Office issues.</remarks>
public static void CloseDoc(this _Document doc)
{
try {
doc.Close(ref dontSave, ref Missing, ref Missing);
doc.Close(ref Missing, ref Missing, ref Missing);
} catch (COMException) {
try {
doc.Close(ref dontSave, ref Missing, ref Missing);
doc.Close(ref dontSave, ref Missing, ref Missing);
} catch (COMException) { }
}
}
示例5: CloseAsync
public static Task CloseAsync(this Logger target)
{
return Task.Factory.StartNew(()=>{
target.Close();
return;
});
}
示例6: ReadOne
public static IDataReader ReadOne(this IDataReader reader, Action<IDataReader> action)
{
if (reader.Read())
action(reader);
reader.Close();
return reader;
}
示例7: PrintToFile
public static void PrintToFile(this FileStream fs, string content)
{
StreamWriter writer = new StreamWriter(fs);
writer.WriteLine(content);
writer.Close();
fs.Close();
}
示例8: smethod_7
public static bool smethod_7(this TcpClient tcpClient_0, string string_0, int int_0, int int_1)
{
IAsyncResult asyncResult = tcpClient_0.BeginConnect(string_0, int_0, null, null);
WaitHandle asyncWaitHandle = asyncResult.AsyncWaitHandle;
bool result;
try
{
if (asyncWaitHandle.WaitOne(int_1))
{
tcpClient_0.EndConnect(asyncResult);
result = true;
}
else
{
tcpClient_0.Close();
result = false;
}
}
catch (SocketException)
{
result = false;
}
finally
{
asyncWaitHandle.Close();
}
return result;
}
示例9: SendWithTimeoutAfter
public static async Task<int> SendWithTimeoutAfter(this UdpClient client, Byte[] list, int delay,
CancellationTokenSource cancel) {
if (client == null)
throw new NullReferenceException();
if (list == null)
throw new ArgumentNullException("list");
var task = client.SendAsync(list, list.Length);
if (task.IsCompleted || (delay == Timeout.Infinite))
return await task;
await Task.WhenAny(task, Task.Delay(delay, cancel.Token)).ConfigureAwait(false);
if (!task.IsCompleted) {
client.Close();
try {
return await task.ConfigureAwait(false);
} catch (ObjectDisposedException) {
throw new TimeoutException("Send timed out.");
}
}
cancel.Cancel(); // Cancel the timer!
return await task.ConfigureAwait(false);
}
示例10: Close
public static void Close(this Solution sol, CloseOptions options)
{
var save = (options & CloseOptions.Save) == CloseOptions.Save;
var wait = (options & CloseOptions.Wait) == CloseOptions.Wait;
sol.Close(save);
if (wait) WaitFor(null, () => sol.IsOpen == false, waitFor: TimeSpan.FromSeconds(20));
}
示例11: CloseSafely
/**--------------------------------------------------------------------------------------------------
<summary> A SqlConnection extension method that closes a safely. </summary>
<param name="con"> The con to act on. </param>
<returns> . </returns>
**/
public static void CloseSafely(this DbConnection con)
{
if (con.State == ConnectionState.Open)
con.Close();
//return con;
}
示例12: GetJObject
public static CouchResponseObject GetJObject(this HttpWebResponse response)
{
var resp = new CouchResponseObject(JObject.Parse(response.GetResponseString()));
resp.StatusCode = (int)response.StatusCode;
response.Close();
return resp;
}
示例13: SpecialClose
public async static void SpecialClose(this Window window)
{
await window.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
window.Close();
});
}
示例14: SafeCloseClientSocket
public static void SafeCloseClientSocket(this Socket client, ILogger logger)
{
if(client == null)
return;
if (!client.Connected)
return;
try
{
client.Shutdown(SocketShutdown.Both);
}
catch(ObjectDisposedException)
{
}
catch(Exception e)
{
if(logger != null)
logger.LogError(e);
}
try
{
client.Close();
}
catch(ObjectDisposedException)
{
}
catch(Exception e)
{
if(logger != null)
logger.LogError(e);
}
}
示例15: CloseOrAbort
/// <summary>
/// Closes the <see cref="ICommunicationObject"/> if it's not in the Faulted state, but Aborts it otherwise.
/// Additionally, if Close throws an expected exception, that exception is swallowed and the operation is Aborted.
/// </summary>
/// <param name="client">The <see cref="ICommunicationObject"/> on which <see cref="ICommunicationObject.Close()"/>
/// or <see cref="ICommunicationObject.Abort()"/> will be called.</param>
/// <remarks>For more details, see:
/// http://msdn2.microsoft.com/en-us/library/aa355056.aspx
/// http://msdn2.microsoft.com/en-us/library/aa354510.aspx
/// http://bloggingabout.net/blogs/erwyn/archive/2006/12/09/WCF-Service-Proxy-Helper.aspx
/// http://blogs.breezetraining.com.au/mickb/2006/12/19/GreatArticleOnWCF.aspx
/// </remarks>
public static void CloseOrAbort(this ICommunicationObject client)
{
if (client.State != CommunicationState.Faulted)
{
// client is in non-faulted state; we can attempt to Close it
try
{
client.Close();
}
catch (CommunicationException)
{
client.Abort();
}
catch (TimeoutException)
{
client.Abort();
}
catch (Exception)
{
// unexpected exception--still Abort the client, but re-throw it
client.Abort();
throw;
}
}
else
{
// client has already failed; have to abort
client.Abort();
}
}