1

こんにちは、次の行でエラーが発生しています。

If Not System.Windows.Clipboard.GetDataObject Is Nothing Then

C# では次のようになると思います

if (System.Windows.Clipboard.GetDataObject!=null) {

エラーは次のとおりです。

「ThreadStateException: OLE 呼び出しを行う前に、現在のスレッドをシングル スレッド アパートメント (STA) モードに設定する必要があります。」

誰でもこれを修正する方法を教えてもらえますか? 「メイン」メソッドに追加するオンラインの提案がいくつか<STAThread()> _ありましたが、これは ASP.NET コントローラー メソッドです。これを追加しようとしましたが、役に立ちませんでした。誰にも提案はありますか?

4

3 に答える 3

1

ASP.NET doesn't really get along with STAThread.

You need an additional task scheduler to run a thread in STA mode to access what you want from the operating system

Take a look at this article it got me going with something like this.

Also, keep in mind that multiple request to your page might mess up things, since you're interacting with the clipboard of the operating system (which runs in another COM context) son concurrency might by risky.

What are you trying to acomplish, maybe there is a better way.

于 2012-11-15T21:19:07.110 に答える
0

最後の注意事項を読むことを忘れないでください。

http://www.telerik.com/community/forums/community-forums/interesting-resources/using-clipboard-class-in-asp-net.aspx

于 2012-11-15T21:22:12.510 に答える
0

これは、/bin ディレクトリ内の古い dll が原因である可能性があります。クリアしてみた?

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/2411f889-8e30-4a6d-9e28-8a46e66c0fdb/

http://www.devnewsgroups.net/windowsforms/t36723-current-thread-must-set-single-thread-apartment-sta.aspx

また、シングル アパートメント モードで新しいスレッドを明示的に開始することもできます。

imports System.Threading

 dim newThread As New Thread(new ThreadStart(AddressOf ThreadMethod))
 newThread.SetApartmentState(ApartmentState.STA);
 newThread.Start();

 'and elsewhere
 Public Sub ThreadMethod()
     If Not System.Windows.Clipboard.GetDataObject Is Nothing Then
        'stuff
     End if
 End Sub
于 2012-11-15T21:24:41.980 に答える