1

この奇妙な問題があります。

メインスレッドにあるコード:

WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler((ss, ee) =>
{
    Dispatcher.BeginInvoke(() =>
    {
        try
        {
            BitmapImage bi = new BitmapImage();
            bi.SetSource(ee.Result);
            WriteableBitmap wb = new WriteableBitmap(bi);
            _okAction.Invoke(linkTexBox.Text, wb);

            theProgressBarDialog.Close();
        }
        catch (Exception)
        {
            theProgressBarDialog.Close();

            string msg = "Cannot fetch the image.  Please make sure the image URL is correct";
            MessageBox.Show(msg);
        }
    });
});
client.OpenReadAsync(new Uri("Image URL without cross domain problem"));
theProgressBarDialog.Show();

画像が正常に読み込まれ、キャンバスにレンダリングされました。

奇妙な動作は、Silverlight アプリケーション全体がフリーズしているように見える場合があり、右クリック以外のユーザー アクションにアプリが応答せず、デフォルトの Silverlight コンテキスト メニューが表示されます。

ボタンが強制的に無効になります。

デバッグ時に例外はスローされません。

編集:を設定client.AllowReadStreamBuffering = falseすると、例外が発生します:

{System.NotSupportedException: Read is not supported on the main thread when buffering is disabled.
   at MS.Internal.InternalNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Windows.Media.Imaging.BitmapSource.ReadStream(Stream streamSource, Byte[]& buffer, Int32& position)
   at System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(Stream streamSource)
   at System.Windows.Media.Imaging.BitmapImage.SetSourceInternal(Stream streamSource)
   at System.Windows.Media.Imaging.BitmapSource.SetSource(Stream streamSource)
   at ToonGui.ImportImageDialog.<>c__DisplayClass2.<OKButton_Click>b__1()}
    [System.NotSupportedException]: {System.NotSupportedException: Read is not supported on the main thread when buffering is disabled.
   at MS.Internal.InternalNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.Windows.Media.Imaging.BitmapSource.ReadStream(Stream streamSource, Byte[]& buffer, Int32& position)
   at System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(Stream streamSource)
   at System.Windows.Media.Imaging.BitmapImage.SetSourceInternal(Stream streamSource)
   at System.Windows.Media.Imaging.BitmapSource.SetSource(Stream streamSource)
   at ToonGui.ImportImageDialog.<>c__DisplayClass2.<OKButton_Click>b__1()}
    Data: {System.Collections.ListDictionaryInternal}
    InnerException: null
    Message: "Read is not supported on the main thread when buffering is disabled."
    StackTrace: "   at MS.Internal.InternalNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)\r\n   at System.Windows.Media.Imaging.BitmapSource.ReadStream(Stream streamSource, Byte[]& buffer, Int32& position)\r\n   at System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(Stream streamSource)\r\n   at System.Windows.Media.Imaging.BitmapImage.SetSourceInternal(Stream streamSource)\r\n   at System.Windows.Media.Imaging.BitmapSource.SetSource(Stream streamSource)\r\n   at ToonGui.ImportImageDialog.<>c__DisplayClass2.<OKButton_Click>b__1()"

BackgroundWorkerダウンロード タスクを別のスレッドで実行するには、クラスを使用する必要がありますか?

4

1 に答える 1

1

みんなありがとう、私はついに答えを見つけました。これはSiverlightのバグであり、Microsoftのせいです。

私の友人の一人が言ったように微软。。。总是有一堆令人想杀人的问题(つまりMicrosoft.... always has some issues that drive you crazy enough so that you want to shoot someone

原因は、theProgressBarDialogこれがChildWindow愚かなバグであることにあります。閉じた後、親ウィンドウ(メインアプリ)が無効のままになることがあります。

  1. Silverlight:Modal ChildWindowは、閉じた後も親を灰色に保ちます:(また、Closeメソッドの代わりにthis.DialogResult = trueを呼び出してみてください。) Silverlight:Modal ChildWindowは、閉じた後も親を灰色に保ちます。

  2. Silverlight 4 ChildWindowは、閉じた後、親を無効のままにします: http ://social.msdn.microsoft.com/Forums/en-US/silverlightbugs/thread/56d0dc0b-3711-4643-b56f-2c94344e3d3a/

解決策は次のとおりです。

        private void ChildWindow_Closed(object sender, System.EventArgs e)
        {
// TODO: should we use apply this fix to all ChildWindow? (make a TnChildWindow)
//   1. Silverlight: Modal ChildWindow keeps parent grayed after closing:
//      (Also try calling this.DialogResult = true instead of the Close method.)
//      https://stackoverflow.com/questions/6456952/silverlight-modal-childwindow-keeps-parent-grayed-after-closing
//   2. Silverlight 4 ChildWindow leaves parent disabled after closing:
//      http://social.msdn.microsoft.com/Forums/en-US/silverlightbugs/thread/56d0dc0b-3711-4643-b56f-2c94344e3d3a/
            Application.Current.RootVisual.SetValue(Control.IsEnabledProperty, true);
        }
于 2013-01-06T09:36:54.980 に答える