diff --git a/Renci.SshClient/Renci.SshNet/BaseClient.cs b/Renci.SshClient/Renci.SshNet/BaseClient.cs
index 3beca30b..e643c5f6 100644
--- a/Renci.SshClient/Renci.SshNet/BaseClient.cs
+++ b/Renci.SshClient/Renci.SshNet/BaseClient.cs
@@ -182,17 +182,19 @@ namespace Renci.SshNet
private void Session_ErrorOccured(object sender, ExceptionEventArgs e)
{
- if (this.ErrorOccurred != null)
+ var handler = this.ErrorOccurred;
+ if (handler != null)
{
- this.ErrorOccurred(this, e);
+ handler(this, e);
}
}
private void Session_HostKeyReceived(object sender, HostKeyEventArgs e)
{
- if (this.HostKeyReceived != null)
+ var handler = this.HostKeyReceived;
+ if (handler != null)
{
- this.HostKeyReceived(this, e);
+ handler(this, e);
}
}
diff --git a/Renci.SshClient/Renci.SshNet/Channels/ChannelDirectTcpip.NET40.cs b/Renci.SshClient/Renci.SshNet/Channels/ChannelDirectTcpip.NET40.cs
index f962c7d0..ac0e8983 100644
--- a/Renci.SshClient/Renci.SshNet/Channels/ChannelDirectTcpip.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/Channels/ChannelDirectTcpip.NET40.cs
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using System;
using System.Net.Sockets;
+using System.Threading;
namespace Renci.SshNet.Channels
{
@@ -11,7 +12,7 @@ namespace Renci.SshNet.Channels
{
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action, TaskCreationOptions.LongRunning);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
partial void InternalSocketReceive(byte[] buffer, ref int read)
diff --git a/Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET40.cs b/Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET40.cs
index 40f1a0f6..5afdebc2 100644
--- a/Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/ForwardedPortDynamic.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -7,7 +8,7 @@ namespace Renci.SshNet
{
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET40.cs b/Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET40.cs
index 37423825..ddbc4d23 100644
--- a/Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/ForwardedPortLocal.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -10,7 +11,7 @@ namespace Renci.SshNet
{
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET40.cs b/Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET40.cs
index 1d57f223..f71a79c3 100644
--- a/Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/ForwardedPortRemote.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -10,7 +11,7 @@ namespace Renci.SshNet
{
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.NET40.cs b/Renci.SshClient/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.NET40.cs
index f0669f95..530c25c4 100644
--- a/Renci.SshClient/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.NET40.cs
@@ -15,7 +15,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/PasswordAuthenticationMethod.NET40.cs b/Renci.SshClient/Renci.SshNet/PasswordAuthenticationMethod.NET40.cs
index 59275a18..22e3f4e2 100644
--- a/Renci.SshClient/Renci.SshNet/PasswordAuthenticationMethod.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/PasswordAuthenticationMethod.NET40.cs
@@ -15,7 +15,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/Session.NET40.cs b/Renci.SshClient/Renci.SshNet/Session.NET40.cs
index 472bbb45..7d7c41f8 100644
--- a/Renci.SshClient/Renci.SshNet/Session.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/Session.NET40.cs
@@ -22,7 +22,7 @@ namespace Renci.SshNet
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action, TaskCreationOptions.LongRunning);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
partial void InternalRegisterMessage(string messageName)
diff --git a/Renci.SshClient/Renci.SshNet/Session.cs b/Renci.SshClient/Renci.SshNet/Session.cs
index 3107c62a..0f036ce0 100644
--- a/Renci.SshClient/Renci.SshNet/Session.cs
+++ b/Renci.SshClient/Renci.SshNet/Session.cs
@@ -1481,9 +1481,10 @@ namespace Renci.SshNet
private void KeyExchange_HostKeyReceived(object sender, HostKeyEventArgs e)
{
- if (this.HostKeyReceived != null)
+ var handler = this.HostKeyReceived;
+ if (handler != null)
{
- this.HostKeyReceived(this, e);
+ handler(this, e);
}
}
diff --git a/Renci.SshClient/Renci.SshNet/SftpClient.NET40.cs b/Renci.SshClient/Renci.SshNet/SftpClient.NET40.cs
index 178f423b..e2807649 100644
--- a/Renci.SshClient/Renci.SshNet/SftpClient.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/SftpClient.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -15,7 +16,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
\ No newline at end of file
diff --git a/Renci.SshClient/Renci.SshNet/Shell.NET40.cs b/Renci.SshClient/Renci.SshNet/Shell.NET40.cs
index 156bda84..e15dab48 100644
--- a/Renci.SshClient/Renci.SshNet/Shell.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/Shell.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -11,7 +12,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/Shell.cs b/Renci.SshClient/Renci.SshNet/Shell.cs
index b5c3a47b..77740e97 100644
--- a/Renci.SshClient/Renci.SshNet/Shell.cs
+++ b/Renci.SshClient/Renci.SshNet/Shell.cs
@@ -212,9 +212,10 @@ namespace Renci.SshNet
private void RaiseError(ExceptionEventArgs e)
{
- if (this.ErrorOccurred != null)
+ var handler = this.ErrorOccurred;
+ if (handler != null)
{
- this.ErrorOccurred(this, e);
+ handler(this, e);
}
}
diff --git a/Renci.SshClient/Renci.SshNet/ShellStream.NET40.cs b/Renci.SshClient/Renci.SshNet/ShellStream.NET40.cs
index d01a9b81..7aa113c5 100644
--- a/Renci.SshClient/Renci.SshNet/ShellStream.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/ShellStream.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -11,7 +12,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/ShellStream.cs b/Renci.SshClient/Renci.SshNet/ShellStream.cs
index c81f38b9..44c9405a 100644
--- a/Renci.SshClient/Renci.SshNet/ShellStream.cs
+++ b/Renci.SshClient/Renci.SshNet/ShellStream.cs
@@ -740,14 +740,20 @@ namespace Renci.SshNet
private void OnRaiseError(ExceptionEventArgs e)
{
- if (this.ErrorOccurred != null)
- this.ErrorOccurred(this, e);
+ var handler = this.ErrorOccurred;
+ if (handler != null)
+ {
+ handler(this, e);
+ }
}
private void OnDataReceived(byte[] data)
{
- if (this.DataReceived != null)
- this.DataReceived(this, new ShellDataEventArgs(data));
+ var handler = this.DataReceived;
+ if (handler != null)
+ {
+ handler(this, new ShellDataEventArgs(data));
+ }
}
}
}
diff --git a/Renci.SshClient/Renci.SshNet/SshCommand.NET40.cs b/Renci.SshClient/Renci.SshNet/SshCommand.NET40.cs
index 411ba5db..356227b5 100644
--- a/Renci.SshClient/Renci.SshNet/SshCommand.NET40.cs
+++ b/Renci.SshClient/Renci.SshNet/SshCommand.NET40.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Renci.SshNet
@@ -11,7 +12,7 @@ namespace Renci.SshNet
/// is null.
partial void ExecuteThread(Action action)
{
- Task.Factory.StartNew(action);
+ ThreadPool.QueueUserWorkItem((o) => { action(); });
}
}
}