しかし、私はそれを個別に実行すると完全に動作します。内部例外:例外をスローするユーザー名とパスワードを入力するたびに、別のスレッドがそれを所有しているため、呼び出しスレッドはこのオブジェクトにアクセスできません。
例外がスロー: 'System.Windows.Markup.XamlParseException' をコード
private void testing()
{
try
{
Thread newWindowThread = new Thread(new ThreadStart(() =>
{
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(
Dispatcher.CurrentDispatcher));
var loading_Win = new Loading_Window();
loading_Win.Show();
loading_Win.Closed += (s, ex) =>
Dispatcher.CurrentDispatcher.BeginInvokeShutdown(
DispatcherPriority.Background);
// Start the Dispatcher Processing
System.Windows.Threading.Dispatcher.Run();
}));
// Set the apartment state
newWindowThread.SetApartmentState(ApartmentState.STA);
// Make the thread a background thread
newWindowThread.IsBackground = true;
// Start the thread
newWindowThread.Start();
}
catch (Exception ex)
{ }
}
PresentationFramework.dll
では、これはロードウィンドウが、これはロード・ウィンドウでCSpublic partial class Loading_Window : MetroWindow
{
public Random rnd = new Random();
public static int intIteration = 1;
private System.Windows.Forms.Timer timer1;
public Loading_Window()
{
InitializeComponent();
InitTimer();
this.Closing += Loading_Window_Closing;
}
private void Loading_Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Process[] pro = null;
//try
//{
// pro = Process.GetProcessesByName("LeanPims");
// pro[0].Kill();
//}
//catch (Exception ex)
//{ }
//Process.GetCurrentProcess().Kill();
}
public void InitTimer()
{
intIteration = 0;
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 300; // in miliseconds
timer1.Start();
}
public void timer1_Tick(object sender, EventArgs e)
{
intIteration += rnd.Next(1, 8);
label1.Content = intIteration.ToString() + " %";
try
{
if (intIteration >= 100)
{
timer1.Stop();
timer1 = null;
this.Close();
}
}
catch (Exception ex) { }
}
}
ですxaml
<Viewbox Stretch="Fill">
<Grid Height="500" Width="700" >
<Image Stretch="Fill" Width="300" Height="350" gif:ImageBehavior.AnimatedSource="Images\Loading1.gif" />
<Rectangle HorizontalAlignment="Left" Height="45" Margin="298,228,0,0" StrokeThickness="2" VerticalAlignment="Top" Width="103" Fill="White"/>
<Label Content="" x:Name="label1" HorizontalAlignment="Left" Height="36" Margin="327,236,0,0" VerticalAlignment="Top" Width="62" FontSize="18" FontFamily="Arial" Foreground="#FF837F7F" Background="{x:Null}" FontWeight="Bold"/>
<Canvas x:Name="c1" HorizontalAlignment="Left" Height="406" Margin="112,38,0,0" VerticalAlignment="Top" Width="481"/>
</Grid>
</Viewbox>
スロー
例外:PresentationFramework.dll
の 'System.Windows.Markup.XamlParseException' 'System.Windows.Controls.Button' の初期設定が例外をスローしました。
どのラインが例外をスローするか、実際にはLoading_Windowは何をしていますか? –
Loding_Win.Show();例外をスローし、ローディングウィンドウは循環的なプログレスバーです.....そのGifファイルはローディングウィンドウのようです。 –
それは奇妙です...私はあなたのコードをダミーの 'Window'でテストしました。さらに、私がリリースしたLOB WPFアプリケーションでも、この正確なコードがうまく機能する場所と同じ原理が使用されています。 'InnerException'のスタックトレースを再確認してください。 '.Show()'が本当の原因なのでしょうか、おそらく 'InnerException'にもう一つの' InnerException'がありますか?あなたは 'Loading_Window'の内容を投稿できますか?非常に具体的なものがそこになければなりません。 – haindl