[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

WPF - worker thread causes crash

ormico

9/25/2008 7:55:00 PM

I have a small WPF application that has a frame that points to a web page on
the internet.

<Window x:Class="WpfWebBrowser.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta...
xmlns:x="http://schemas.microsoft.com/winfx/2006/...
Title="Window1" Height="800" Width="1118" WindowState="Maximized">
<Grid Name="grMain">
<Frame Name="frmDisplay" NavigationUIVisibility="Visible"
Margin="0,0,0,50" Source="http://example.... />
<Button Name="btRefresh" Width="100" Height="32"
Click="btRefresh_Click" HorizontalAlignment="Left" Margin="12,0,0,12"
VerticalAlignment="Bottom">0</Button>
<Button Name="btClose" Width="100" Height="32" Click="btClose_Click"
HorizontalAlignment="Left" Margin="118,0,0,12"
VerticalAlignment="Bottom">Close</Button>
</Grid>
</Window>

I also have a System.Timer.Timer that goes off after 1 minute. If I try to
modify an object on the page it generates an error and crashes the program.
This is an error that I cannot catch with a try catch block. It crashes the
program anyway and prompts me to send the crash info to microsoft.

If I remove the Frame, no error is generated.

public Window1()
{
InitializeComponent();

timer2 = new System.Threading.Timer(timer2_Callback);

timer2.Change((int)(TimeSpan.FromMinutes(1.0).TotalMilliseconds), 0);
}

void timer2_Callback(object state)
{
this.Dispatcher.Invoke((Action)(delegate()
{
btRefresh.Content = "blah";
}));
}

What I am ultimatly try to accomplish is an application that displays a web
page for a certain amount of time, then closes. I would like to put this in
an appdomain that gets reloaded after it closes each time. This is because
when the web page runs for a while in IE it will consume more and more
memory. I want to be able to unload the page wit the web browser control to
free the memory and then reopen and go back to the page. Most of this is
working but I can't get the wpf page with the webbrowser control to close
after a certain amount of time because when I call this.Close() or
Application.Current.Shutdown() it crashes. I get the same behavior if I try
to access any other controls also.
4 Answers

Peter Duniho

9/25/2008 8:22:00 PM

0

On Thu, 25 Sep 2008 12:55:01 -0700, ormico
<ormico@discussions.microsoft.com> wrote:

> [...]
> I also have a System.Timer.Timer that goes off after 1 minute. If I try
> to
> modify an object on the page it generates an error and crashes the
> program.
> This is an error that I cannot catch with a try catch block. It crashes
> the
> program anyway and prompts me to send the crash info to microsoft.

I can't say that I'm confident I'd personally have an answer anyway,
having as little experience with WPF as I do. But, I'll point out that
with the little information you've provided so far, it's hard to see how
_anyone_ could answer the question.

You say you get an error/exception, but you don't provide any details of
the error. You haven't posted a concise-but-complete code sample
demonstrating the problem, so there's no reliable way for anyone to try to
reproduce the problem themselves. And you say that you can't catch the
error with a try/catch block, but you haven't posted any code with a
try/catch block, so there's no way for anyone to know what you tried and
why it might or might not have worked.

If you are earnest about getting an answer to your question posted here, I
suggest that you provide enough elaboration to the question that someone
might be able to reasonably provide that answer.

Pete

ormico

9/25/2008 8:52:00 PM

0

Thanks for responding just to let me know that you know very little about my
problem but that you just wanted to complain anyway.

Thanks. That was constructive.

The error I recieved, as stated in the original post, is the Windows Crash
dialog that prompts you to send the error information to Microsoft. If you
click "What does this error report containt?" you are presented with an Error
Signature. The only part that looks useful is "P9 :
system.missingmethodexception"

Further, you can click "View the contents of the Error Report" but its about
10 pages of nothing useful.

I left the exception handling out so the code would be easier to read. Here
it is with the exception handling added back. Please note in the example
below that I do not try do do anything with the exception except catch it.
This is to be sure that I'm not introducing the exception in the catch block.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfWebBrowser
{
class Startup
{
[STAThread()]
[LoaderOptimization(LoaderOptimization.MultiDomainHost)]
static void Main()
{
try
{
App app = new App();
app.MainWindow = new Window1();
app.MainWindow.Show();
app.Run();
}
catch (Exception)
{

throw;
}
}
}

}

public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();

timer2 = new System.Threading.Timer(timer2_Callback);

timer2.Change((int)(TimeSpan.FromMinutes(1.0).TotalMilliseconds), 0);
}

void timer2_Callback(object state)
{
try
{
this.Dispatcher.Invoke((Action)(delegate()
{
btRefresh.Content = "blah";
}));
}
catch (Exception)
{

throw;
}
}

System.Threading.Timer timer2 = null;

private void btRefresh_Click(object sender, RoutedEventArgs e)
{
frmDisplay.Navigate(new Uri("http://example....));
}

private void btClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}



"Peter Duniho" wrote:

> On Thu, 25 Sep 2008 12:55:01 -0700, ormico
> <ormico@discussions.microsoft.com> wrote:
>
> > [...]
> > I also have a System.Timer.Timer that goes off after 1 minute. If I try
> > to
> > modify an object on the page it generates an error and crashes the
> > program.
> > This is an error that I cannot catch with a try catch block. It crashes
> > the
> > program anyway and prompts me to send the crash info to microsoft.
>
> I can't say that I'm confident I'd personally have an answer anyway,
> having as little experience with WPF as I do. But, I'll point out that
> with the little information you've provided so far, it's hard to see how
> _anyone_ could answer the question.
>
> You say you get an error/exception, but you don't provide any details of
> the error. You haven't posted a concise-but-complete code sample
> demonstrating the problem, so there's no reliable way for anyone to try to
> reproduce the problem themselves. And you say that you can't catch the
> error with a try/catch block, but you haven't posted any code with a
> try/catch block, so there's no way for anyone to know what you tried and
> why it might or might not have worked.
>
> If you are earnest about getting an answer to your question posted here, I
> suggest that you provide enough elaboration to the question that someone
> might be able to reasonably provide that answer.
>
> Pete
>

ormico

9/25/2008 9:01:00 PM

0

my last post had 2 typos
here is the corrected text

class Startup
{
[STAThread()]
[LoaderOptimization(LoaderOptimization.MultiDomainHost)]
static void Main()
{
//CrossAppDomainDelegate action = () =>
//{
// App app = new App();
// app.MainWindow = new Window1();
// app.MainWindow.Show();
// app.Run();
//};

//for (int i = 0; i < 10; i++)
//{
// try
// {
// AppDomain domain = AppDomain.CreateDomain("another
domain");
// domain.DoCallBack(action);
// }
// catch (Exception ex)
// {

// }
//}

try
{
App app = new App();
app.MainWindow = new Window1();
app.MainWindow.Show();
app.Run();
}
catch (Exception)
{

}
}
}


public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();

timer2 = new System.Threading.Timer(timer2_Callback);

timer2.Change((int)(TimeSpan.FromMinutes(1.0).TotalMilliseconds), 0);
}

void timer2_Callback(object state)
{
try
{
this.Dispatcher.Invoke((Action)(delegate()
{
btRefresh.Content = "blah";
}));
}
catch (Exception)
{

}
}

System.Threading.Timer timer2 = null;

private void btRefresh_Click(object sender, RoutedEventArgs e)
{
frmDisplay.Navigate(new Uri("http://example....));
}

private void btClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}

Peter Duniho

9/25/2008 9:06:00 PM

0

On Thu, 25 Sep 2008 13:52:01 -0700, ormico
<ormico@discussions.microsoft.com> wrote:

> Thanks for responding just to let me know that you know very little
> about my
> problem but that you just wanted to complain anyway.

I was not complaining. There was _nothing_ in my post that was a
complaint. I am trying to help you.

However, with your attitude, you don't appear to be the sort of person
deserving of much help. Good luck with that.