• Create Account

### #Actualmaya18222

Posted 01 January 2013 - 11:06 AM

Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.

My first approach was just

DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(1);
dt.Tick += new EventHandler(OnProcessViewports);
dt.Start();

which as mentioned, gives me arounf 60 FPS.

Ive now tried

Loaded += (s, a) =>
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (ss, aa) =>
{
while (true)
{
Dispatcher.Invoke(new EventHandler(OnProcessViewports), new object[] { null, null });
}
};
bw.RunWorkerAsync();
};

This works, and gives me several hundred FPS (with a low sleep time), which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.

using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.

### #5maya18222

Posted 01 January 2013 - 11:06 AM

<p>Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.<br />
<br />
My first approach was just</p>
<pre class="_prettyXprint _lang-auto _linenums:1">
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(1);
dt.Tick += new EventHandler(OnProcessViewports);
dt.Start();</pre>
<p>which as mentioned, gives me arounf 60 FPS.<br />
<br />
Ive now tried</p>
<pre class="_prettyXprint _lang-auto _linenums:1">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackgroundWorker bw = new BackgroundWorker();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bw.DoWork += (ss, aa) =&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (true)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dispatcher.Invoke(new EventHandler(OnProcessViewports), new object[] { null, null });
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bw.RunWorkerAsync();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</pre>
<p>This works, and gives me several hundred FPS (with a low sleep time), which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.<br />
<br />
using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.</p>

### #4maya18222

Posted 01 January 2013 - 11:04 AM

Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.

My first approach was just

DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(1);
dt.Tick += new EventHandler(OnProcessViewports);
dt.Start();

which as mentioned, gives me arounf 60 FPS.

Ive now tried

Loaded += (s, a) =>
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (ss, aa) =>
{
while (true)
{
Dispatcher.Invoke(new EventHandler(OnProcessViewports), new object[] { null, null });
}
};
bw.RunWorkerAsync();
};

This works, and gives me several hundred FPS, which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.

using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.

### #3maya18222

Posted 01 January 2013 - 11:01 AM

Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.

My first approach was just
DispatcherTimer dt = new DispatcherTimer();dt.Interval = TimeSpan.FromMilliseconds(1);dt.Tick += new EventHandler(OnProcessWinFormsControls);dt.Start();
which as mentioned, gives me arounf 60 FPS.

Ive now tried
WPFWindowConstructor(){            Loaded += (s, a) =>            {                BackgroundWorker bw = new BackgroundWorker();                bw.DoWork += (ss, aa) =>                {                    while (true)                    {                        Thread.Sleep(1);                        Dispatcher.Invoke(new EventHandler(OnProcessWinFormsControls), new object[] { null, null });                    }                };                bw.RunWorkerAsync();            };}
This works, and gives me several hundred FPS, which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.

using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.

### #2maya18222

Posted 01 January 2013 - 11:01 AM

Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.

My first approach was just
DispatcherTimer dt = new DispatcherTimer();dt.Interval = TimeSpan.FromMilliseconds(1);dt.Tick += new EventHandler(OnProcessWinFormsControls);dt.Start();
which as mentioned, gives me arounf 60 FPS.

Ive now tried
WPFWindowConstructor(){            Loaded += (s, a) =>            {                BackgroundWorker bw = new BackgroundWorker();                bw.DoWork += (ss, aa) =>                {                    while (true)                    {                        Thread.Sleep(1);                        Dispatcher.Invoke(new EventHandler(OnProcessWinFormsControls), new object[] { null, null });                    }                };                bw.RunWorkerAsync();            };}
This works, and gives me several hundred FPS, which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.

using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.

### #1maya18222

Posted 01 January 2013 - 10:59 AM

Thank you for the replies. Im actually trying to come up with a way of updating winForms controls in a wpf application at a rate of several hundred FPS.

My first approach was just

DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromMilliseconds(1);
dt.Tick += new EventHandler(OnProcessViewports);
dt.Start();

which as mentioned, gives me arounf 60 FPS.

Ive now tried


WPFWindowConstructor()
{
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (ss, aa) =>
{
while (true)
{
Dispatcher.Invoke(new EventHandler(OnProcessWinFormsControls), new object[] { null, null });
}
};
bw.RunWorkerAsync();
};
}

This works, and gives me several hundred FPS, which is what I wanted. But, something odd is happeneing with the CPU usage. If I set the sleep time to about 16ms, then I get around ~55FPS, but, .. the CPU usage goes to about 20-30%.

using the dispatch timer approach as coded above, I get 60 FPS, and around 2-3% CPU usage. Any ideas why this would be the case? Both versions run at around 60FPS, yet the 2nd approach uses a lot more CPU usage.

PARTNERS