473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disposable Canvas?

OK, why is Canvas not IDisposable, and how do I get rid of all the Windows
handles?

I'm doing a performance test of looping through a dynamic XAML-to-JPEG
conversion. It gets to about 500 conversions and then crashes. Task Manager
says that about 6000 Windows handles were created and the count never
decrements.

My code (loop not shown):

protected System.IO.Strea m GenImageStream( )
{
System.IO.Strea m retImageStream = null;
System.IO.Strea mReader sr = new
System.IO.Strea mReader("Window 1.xaml");
string xaml = sr.ReadToEnd();
if (text != null)
{
xaml = xaml.Replace("{ $TEXT$}", text
}
else
{
xaml = xaml.Replace("{ $TEXT$}", "Enter text.");
}
sr.Close();
System.IO.Memor yStream ms = new
System.IO.Memor yStream(xaml.Le ngth);
System.IO.Strea mWriter sw = new System.IO.Strea mWriter(ms);
sw.Write(xaml);
sw.Flush();
ms.Seek(0, System.IO.SeekO rigin.Begin);
System.Windows. Controls.Canvas canvas =
(System.Windows .Controls.Canva s)
System.Windows. Markup.XamlRead er.Load(ms);
canvas.Backgrou nd = System.Windows. Media.Brushes.Y ellow;
canvas.Measure( new System.Windows. Size(640d, 480d));
canvas.Arrange( new System.Windows. Rect(0d, 0d, 640d, 480d));
System.Windows. Media.Imaging.R enderTargetBitm ap rtb
= new System.Windows. Media.Imaging.R enderTargetBitm ap(
640, 480, 96d, 96d,
System.Windows. Media.PixelForm ats.Default);
rtb.Render(canv as);
System.Windows. Media.Imaging.J pegBitmapEncode r encoder
= new System.Windows. Media.Imaging.J pegBitmapEncode r();
encoder.Frames. Add(System.Wind ows.Media.Imagi ng.BitmapFrame. Create(rtb));
string fp = Request.Physica lApplicationPat h + "imgtmp\\"
+ (Guid.NewGuid() ).ToString() + ".jpg";
retImageStream = new System.IO.Memor yStream();
encoder.Save(re tImageStream);
retImageStream. Seek(0, System.IO.SeekO rigin.Begin);
ms.Dispose();
}

Jon

May 4 '07 #1
26 3604
Hi,

Jon Davis wrote:
OK, why is Canvas not IDisposable, and how do I get rid of all the Windows
handles?
I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to. I also used a
profiler to look out for resource leaks and I didn't find any of these
either. Here's the code I used:

private void OnButtonClick( object sender, RoutedEventArgs e) {
for (int i = 0; i < 1000; i++)
GenImageStream( );
}
private static string GetXaml( ) {
StreamReader sr = new StreamReader("C anvas.xaml");
string xaml = sr.ReadToEnd( );
sr.Close( );
return xaml;
}

protected void GenImageStream( ) {
string xaml = GetXaml( );

using (MemoryStream ms = new MemoryStream(xa ml.Length)) {
StreamWriter sw = new StreamWriter(ms );
sw.Write(xaml);
sw.Flush( );
ms.Seek(0, SeekOrigin.Begi n);

Canvas canvas = (Canvas) XamlReader.Load (ms);
canvas.Backgrou nd = Brushes.Yellow;
canvas.Measure( new Size(640d, 480d));
canvas.Arrange( new Rect(0d, 0d, 640d, 480d));
RenderTargetBit map rtb = new RenderTargetBit map(
640, 480, 96d, 96d, PixelFormats.De fault);
rtb.Render(canv as);
JpegBitmapEncod er encoder = new JpegBitmapEncod er( );
encoder.Frames. Add(BitmapFrame .Create(rtb));
using (Stream outstream = new MemoryStream( ))
encoder.Save(ou tstream);
}
}
Oliver Sturm
--
http://www.sturmnet.org/blog - MVP C#
May 4 '07 #2

"Oliver Sturm [MVP C#]" <ol****@sturmne t.orgwrote in message
news:1o******** ********@sturmn et.org...
Hi,

Jon Davis wrote:
>OK, why is Canvas not IDisposable, and how do I get rid of all the
Windows
handles?

I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to.
That's interesting. It might help if I mention I'm trying to do this on an
ASP.NET web page to see about the feasibility of dynamically-generating
images from XAML mark-up, on a heavily impacted web site. The output of
this is great and seems to be fast, it's just that it crashes after 500
times and IIS's process has 6000 Windows handles. I'm executing on Windows
Vista / IIS 7. Here's the full source. I'll take a look at yours as well,
but in the mean time ... maybe you can spot something really, really stupid
I'm doing? :)

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace ImageGenServer
{
public partial class GenImage : System.Web.UI.P age
{
private System.IO.Strea m retImageStream;
protected void Page_Load(objec t sender, EventArgs e)
{
Gimme();
}

protected void Gimme()
{
System.Threadin g.Thread thread = new System.Threadin g.Thread(
GimmeMore);
thread.SetApart mentState(Syste m.Threading.Apa rtmentState.STA );
thread.Start();
while (thread.IsAlive )
{
System.Threadin g.Thread.Sleep( 0);
}
Response.Conten tType = "image/jpeg";
System.IO.Binar yReader br = new
System.IO.Binar yReader(retImag eStream);
Response.Binary Write(br.ReadBy tes((int)retIma geStream.Length ));
br.Close();
retImageStream. Close();
Response.Flush( );

thread = null;
br = null;
retImageStream = null;

Response.End();
}

protected void GimmeMore()
{
System.IO.Strea mReader sr = new
System.IO.Strea mReader(Request .PhysicalApplic ationPath + "Window1.xaml") ;
string xaml = sr.ReadToEnd();
if (Request["text"] != null)
{
xaml = xaml.Replace("{ $TEXT$}", Request["text"]);
}
else
{
xaml = xaml.Replace("{ $TEXT$}", "Add &quot;text=...& quot; to
querystring.");
}
sr.Close();
System.IO.Memor yStream ms = new
System.IO.Memor yStream(xaml.Le ngth);
System.IO.Strea mWriter sw = new System.IO.Strea mWriter(ms);
sw.Write(xaml);
sw.Flush();
ms.Seek(0, System.IO.SeekO rigin.Begin);
System.Windows. Controls.Canvas canvas =
(System.Windows .Controls.Canva s)
System.Windows. Markup.XamlRead er.Load(
ms);
canvas.Backgrou nd = System.Windows. Media.Brushes.Y ellow;
canvas.Measure( new System.Windows. Size(640d, 480d));
canvas.Arrange( new System.Windows. Rect(0d, 0d, 640d, 480d));
System.Windows. Media.Imaging.R enderTargetBitm ap rtb
= new System.Windows. Media.Imaging.R enderTargetBitm ap(
640, 480, 96d, 96d,
System.Windows. Media.PixelForm ats.Default);
rtb.Render(canv as);
System.Windows. Media.Imaging.J pegBitmapEncode r encoder
= new System.Windows. Media.Imaging.J pegBitmapEncode r();
encoder.Frames. Add(System.Wind ows.Media.Imagi ng.BitmapFrame. Create(
rtb));
string fp = Request.Physica lApplicationPat h + "imgtmp\\"
+ (Guid.NewGuid() ).ToString() + ".jpg";
retImageStream = new System.IO.Memor yStream();
encoder.Save(re tImageStream);
retImageStream. Seek(0, System.IO.SeekO rigin.Begin);
ms.Dispose();

}
}
}
May 4 '07 #3
Died with you code, too. I think this has to do with STA threading. Not sure
if there is such a thing as a "best practice" for STA threading on ASP.NET.

Jon
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
>
"Oliver Sturm [MVP C#]" <ol****@sturmne t.orgwrote in message
news:1o******** ********@sturmn et.org...
>Hi,

Jon Davis wrote:
>>OK, why is Canvas not IDisposable, and how do I get rid of all the
Windows
handles?

I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to.

That's interesting. It might help if I mention I'm trying to do this on an
ASP.NET web page to see about the feasibility of dynamically-generating
images from XAML mark-up, on a heavily impacted web site. The output of
this is great and seems to be fast, it's just that it crashes after 500
times and IIS's process has 6000 Windows handles. I'm executing on Windows
Vista / IIS 7. Here's the full source. I'll take a look at yours as well,
but in the mean time ... maybe you can spot something really, really
stupid I'm doing? :)

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace ImageGenServer
{
public partial class GenImage : System.Web.UI.P age
{
private System.IO.Strea m retImageStream;
protected void Page_Load(objec t sender, EventArgs e)
{
Gimme();
}

protected void Gimme()
{
System.Threadin g.Thread thread = new System.Threadin g.Thread(
GimmeMore);
thread.SetApart mentState(Syste m.Threading.Apa rtmentState.STA );
thread.Start();
while (thread.IsAlive )
{
System.Threadin g.Thread.Sleep( 0);
}
Response.Conten tType = "image/jpeg";
System.IO.Binar yReader br = new
System.IO.Binar yReader(retImag eStream);
Response.Binary Write(br.ReadBy tes((int)retIma geStream.Length ));
br.Close();
retImageStream. Close();
Response.Flush( );

thread = null;
br = null;
retImageStream = null;

Response.End();
}

protected void GimmeMore()
{
System.IO.Strea mReader sr = new
System.IO.Strea mReader(Request .PhysicalApplic ationPath + "Window1.xaml") ;
string xaml = sr.ReadToEnd();
if (Request["text"] != null)
{
xaml = xaml.Replace("{ $TEXT$}", Request["text"]);
}
else
{
xaml = xaml.Replace("{ $TEXT$}", "Add &quot;text=...& quot;
to querystring.");
}
sr.Close();
System.IO.Memor yStream ms = new
System.IO.Memor yStream(xaml.Le ngth);
System.IO.Strea mWriter sw = new System.IO.Strea mWriter(ms);
sw.Write(xaml);
sw.Flush();
ms.Seek(0, System.IO.SeekO rigin.Begin);
System.Windows. Controls.Canvas canvas =
(System.Windows .Controls.Canva s)
System.Windows. Markup.XamlRead er.Load(
ms);
canvas.Backgrou nd = System.Windows. Media.Brushes.Y ellow;
canvas.Measure( new System.Windows. Size(640d, 480d));
canvas.Arrange( new System.Windows. Rect(0d, 0d, 640d, 480d));
System.Windows. Media.Imaging.R enderTargetBitm ap rtb
= new System.Windows. Media.Imaging.R enderTargetBitm ap(
640, 480, 96d, 96d,
System.Windows. Media.PixelForm ats.Default);
rtb.Render(canv as);
System.Windows. Media.Imaging.J pegBitmapEncode r encoder
= new System.Windows. Media.Imaging.J pegBitmapEncode r();

encoder.Frames. Add(System.Wind ows.Media.Imagi ng.BitmapFrame. Create(
rtb));
string fp = Request.Physica lApplicationPat h + "imgtmp\\"
+ (Guid.NewGuid() ).ToString() + ".jpg";
retImageStream = new System.IO.Memor yStream();
encoder.Save(re tImageStream);
retImageStream. Seek(0, System.IO.SeekO rigin.Begin);
ms.Dispose();

}
}
}

May 4 '07 #4
Setting AspCompat="true " to the .aspx header to make the page STA threaded,
and dropping the spawning of a new thread, seemed to alleviate this
significantly. I executed 5000 times before I just killed the test (was
running low on drive space -- made that many images). Memory consumption by
the VS debugger web server did go up to 178MB and more than 1000 handles and
didn't go down after I stopped the test, so there's still a bad memory leak,
but not anything like before.

Interesting. However, now I get an error message in Visual Studio when I go
to debug:

Error connecting to undo manager of source file 'C:\Documents and
Settings\jdavis \My Documents\Visua l Studio
2005\Projects\I mageGenServer\T hreadMode.aspx. designer.cs'.
Jon
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
Died with you code, too. I think this has to do with STA threading. Not
sure if there is such a thing as a "best practice" for STA threading on
ASP.NET.

Jon
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
>>
"Oliver Sturm [MVP C#]" <ol****@sturmne t.orgwrote in message
news:1o******* *********@sturm net.org...
>>Hi,

Jon Davis wrote:

OK, why is Canvas not IDisposable, and how do I get rid of all the
Windows
handles?

I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to.

That's interesting. It might help if I mention I'm trying to do this on
an ASP.NET web page to see about the feasibility of
dynamically-generating images from XAML mark-up, on a heavily impacted
web site. The output of this is great and seems to be fast, it's just
that it crashes after 500 times and IIS's process has 6000 Windows
handles. I'm executing on Windows Vista / IIS 7. Here's the full source.
I'll take a look at yours as well, but in the mean time ... maybe you can
spot something really, really stupid I'm doing? :)

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace ImageGenServer
{
public partial class GenImage : System.Web.UI.P age
{
private System.IO.Strea m retImageStream;
protected void Page_Load(objec t sender, EventArgs e)
{
Gimme();
}

protected void Gimme()
{
System.Threadin g.Thread thread = new System.Threadin g.Thread(
GimmeMore);
thread.SetApart mentState(Syste m.Threading.Apa rtmentState.STA );
thread.Start();
while (thread.IsAlive )
{
System.Threadin g.Thread.Sleep( 0);
}
Response.Conten tType = "image/jpeg";
System.IO.Binar yReader br = new
System.IO.Bina ryReader(retIma geStream);

Response.Binar yWrite(br.ReadB ytes((int)retIm ageStream.Lengt h));
br.Close();
retImageStream. Close();
Response.Flush( );

thread = null;
br = null;
retImageStream = null;

Response.End();
}

protected void GimmeMore()
{
System.IO.Strea mReader sr = new
System.IO.Stre amReader(Reques t.PhysicalAppli cationPath + "Window1.xaml") ;
string xaml = sr.ReadToEnd();
if (Request["text"] != null)
{
xaml = xaml.Replace("{ $TEXT$}", Request["text"]);
}
else
{
xaml = xaml.Replace("{ $TEXT$}", "Add &quot;text=...& quot;
to querystring.");
}
sr.Close();
System.IO.Memor yStream ms = new
System.IO.Memo ryStream(xaml.L ength);
System.IO.Strea mWriter sw = new System.IO.Strea mWriter(ms);
sw.Write(xaml);
sw.Flush();
ms.Seek(0, System.IO.SeekO rigin.Begin);
System.Windows. Controls.Canvas canvas =
(System.Window s.Controls.Canv as)
System.Windows. Markup.XamlRead er.Load(
ms);
canvas.Backgrou nd = System.Windows. Media.Brushes.Y ellow;
canvas.Measure( new System.Windows. Size(640d, 480d));
canvas.Arrange( new System.Windows. Rect(0d, 0d, 640d, 480d));
System.Windows. Media.Imaging.R enderTargetBitm ap rtb
= new System.Windows. Media.Imaging.R enderTargetBitm ap(
640, 480, 96d, 96d,
System.Windows .Media.PixelFor mats.Default);
rtb.Render(canv as);
System.Windows. Media.Imaging.J pegBitmapEncode r encoder
= new System.Windows. Media.Imaging.J pegBitmapEncode r();

encoder.Frames .Add(System.Win dows.Media.Imag ing.BitmapFrame .Create(
rtb));
string fp = Request.Physica lApplicationPat h + "imgtmp\\"
+ (Guid.NewGuid() ).ToString() + ".jpg";
retImageStream = new System.IO.Memor yStream();
encoder.Save(re tImageStream);
retImageStream. Seek(0, System.IO.SeekO rigin.Begin);
ms.Dispose();

}
}
}


May 4 '07 #5
Setting AspCompat="true " to the .aspx header to make the page STA threaded,
and dropping the spawning of a new thread, seemed to alleviate this
significantly. I executed 5000 times before I just killed the test (was
running low on drive space -- made that many images). Memory consumption by
the VS debugger web server did go up to 178MB and more than 1000 handles and
didn't go down after I stopped the test, so there's still a bad memory leak,
but not anything like before.

Would like to fix that lingering memory leak. The stuff HAS to be flushed or
else it's no good for production use, unless I want to reset IIS every hour
(which I don't).

Jon

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:%2******** *******@TK2MSFT NGP05.phx.gbl.. .
Died with you code, too. I think this has to do with STA threading. Not
sure if there is such a thing as a "best practice" for STA threading on
ASP.NET.

Jon
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:ex******** ******@TK2MSFTN GP05.phx.gbl...
>>
"Oliver Sturm [MVP C#]" <ol****@sturmne t.orgwrote in message
news:1o******* *********@sturm net.org...
>>Hi,

Jon Davis wrote:

OK, why is Canvas not IDisposable, and how do I get rid of all the
Windows
handles?

I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to.

That's interesting. It might help if I mention I'm trying to do this on
an ASP.NET web page to see about the feasibility of
dynamically-generating images from XAML mark-up, on a heavily impacted
web site. The output of this is great and seems to be fast, it's just
that it crashes after 500 times and IIS's process has 6000 Windows
handles. I'm executing on Windows Vista / IIS 7. Here's the full source.
I'll take a look at yours as well, but in the mean time ... maybe you can
spot something really, really stupid I'm doing? :)

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace ImageGenServer
{
public partial class GenImage : System.Web.UI.P age
{
private System.IO.Strea m retImageStream;
protected void Page_Load(objec t sender, EventArgs e)
{
Gimme();
}

protected void Gimme()
{
System.Threadin g.Thread thread = new System.Threadin g.Thread(
GimmeMore);
thread.SetApart mentState(Syste m.Threading.Apa rtmentState.STA );
thread.Start();
while (thread.IsAlive )
{
System.Threadin g.Thread.Sleep( 0);
}
Response.Conten tType = "image/jpeg";
System.IO.Binar yReader br = new
System.IO.Bina ryReader(retIma geStream);

Response.Binar yWrite(br.ReadB ytes((int)retIm ageStream.Lengt h));
br.Close();
retImageStream. Close();
Response.Flush( );

thread = null;
br = null;
retImageStream = null;

Response.End();
}

protected void GimmeMore()
{
System.IO.Strea mReader sr = new
System.IO.Stre amReader(Reques t.PhysicalAppli cationPath + "Window1.xaml") ;
string xaml = sr.ReadToEnd();
if (Request["text"] != null)
{
xaml = xaml.Replace("{ $TEXT$}", Request["text"]);
}
else
{
xaml = xaml.Replace("{ $TEXT$}", "Add &quot;text=...& quot;
to querystring.");
}
sr.Close();
System.IO.Memor yStream ms = new
System.IO.Memo ryStream(xaml.L ength);
System.IO.Strea mWriter sw = new System.IO.Strea mWriter(ms);
sw.Write(xaml);
sw.Flush();
ms.Seek(0, System.IO.SeekO rigin.Begin);
System.Windows. Controls.Canvas canvas =
(System.Window s.Controls.Canv as)
System.Windows. Markup.XamlRead er.Load(
ms);
canvas.Backgrou nd = System.Windows. Media.Brushes.Y ellow;
canvas.Measure( new System.Windows. Size(640d, 480d));
canvas.Arrange( new System.Windows. Rect(0d, 0d, 640d, 480d));
System.Windows. Media.Imaging.R enderTargetBitm ap rtb
= new System.Windows. Media.Imaging.R enderTargetBitm ap(
640, 480, 96d, 96d,
System.Windows .Media.PixelFor mats.Default);
rtb.Render(canv as);
System.Windows. Media.Imaging.J pegBitmapEncode r encoder
= new System.Windows. Media.Imaging.J pegBitmapEncode r();

encoder.Frames .Add(System.Win dows.Media.Imag ing.BitmapFrame .Create(
rtb));
string fp = Request.Physica lApplicationPat h + "imgtmp\\"
+ (Guid.NewGuid() ).ToString() + ".jpg";
retImageStream = new System.IO.Memor yStream();
encoder.Save(re tImageStream);
retImageStream. Seek(0, System.IO.SeekO rigin.Begin);
ms.Dispose();

}
}
}


May 4 '07 #6
"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:em******** ******@TK2MSFTN GP02.phx.gbl...
Setting AspCompat="true " to the .aspx header to make the page STA
threaded,
and dropping the spawning of a new thread, seemed to alleviate this
significantly. I executed 5000 times before I just killed the test (was
running low on drive space -- made that many images). Memory consumption
by
the VS debugger web server did go up to 178MB and more than 1000 handles
and
didn't go down after I stopped the test, so there's still a bad memory
leak,
but not anything like before.

Would like to fix that lingering memory leak. The stuff HAS to be flushed
or else it's no good for production use, unless I want to reset IIS every
hour (which I don't).

Jon

XAML and WPF is a desktop technology and IMO not designed and not supported
server side, note that the same applies to System.Windows. Forms. A lot of
the System.Windows namespace classes need a pumping STA thread to run in,
and the System.Windows. Markup.XamlRead er should throw an exception when
called from a non-STA thread (don't know why it didn't in your case though).
The documentation should include a warning just like the one included in
Windows.Forms
<Classes within the Windows Forms namespace are not supported for use within
a Windows service. Trying to use these classes from within a service may
produce unexpected problems, such as diminished service performance and
run-time exceptions.
>


Willy.

May 4 '07 #7
Oliver,

I'm running your code in a console app now and watching memory consumption
go up in a similar way to IIS. Handle count is frozen solid at 151, but
memory utilization is currently at 271MB at 10000 instances of the loop.
GC.Collect() after the loop completed had no significant effect; took it to
245MB on second pass.

Jon
"Oliver Sturm [MVP C#]" <ol****@sturmne t.orgwrote in message
news:1o******** ********@sturmn et.org...
Hi,

Jon Davis wrote:
>OK, why is Canvas not IDisposable, and how do I get rid of all the
Windows
handles?

I used a variation of your code to try this myself, but I was unable to
reproduce the crash behaviour your were referring to. I also used a
profiler to look out for resource leaks and I didn't find any of these
either. Here's the code I used:

private void OnButtonClick( object sender, RoutedEventArgs e) {
for (int i = 0; i < 1000; i++)
GenImageStream( );
}
private static string GetXaml( ) {
StreamReader sr = new StreamReader("C anvas.xaml");
string xaml = sr.ReadToEnd( );
sr.Close( );
return xaml;
}

protected void GenImageStream( ) {
string xaml = GetXaml( );

using (MemoryStream ms = new MemoryStream(xa ml.Length)) {
StreamWriter sw = new StreamWriter(ms );
sw.Write(xaml);
sw.Flush( );
ms.Seek(0, SeekOrigin.Begi n);

Canvas canvas = (Canvas) XamlReader.Load (ms);
canvas.Backgrou nd = Brushes.Yellow;
canvas.Measure( new Size(640d, 480d));
canvas.Arrange( new Rect(0d, 0d, 640d, 480d));
RenderTargetBit map rtb = new RenderTargetBit map(
640, 480, 96d, 96d, PixelFormats.De fault);
rtb.Render(canv as);
JpegBitmapEncod er encoder = new JpegBitmapEncod er( );
encoder.Frames. Add(BitmapFrame .Create(rtb));
using (Stream outstream = new MemoryStream( ))
encoder.Save(ou tstream);
}
}
Oliver Sturm
--
http://www.sturmnet.org/blog - MVP C#

May 4 '07 #8

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:70******** *************** ***********@mic rosoft.com...
XAML and WPF is a desktop technology and IMO not designed and not
supported server side, note that the same applies to System.Windows. Forms.
I know. This was a feasibility test.

Jon
May 4 '07 #9

"Jon Davis" <jo*@REMOVE.ME. PLEASE.jondavis .netwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Oliver,

I'm running your code in a console app now and watching memory consumption
go up in a similar way to IIS. Handle count is frozen solid at 151, but
memory utilization is currently at 271MB at 10000 instances of the loop.
GC.Collect() after the loop completed had no significant effect; took it
to 245MB on second pass.

Jon
OK, I think in conclusion a service that does what I'm considering might
still be feasible but there's some plumbing to be done. If Windows itself
can clear out the memory when the process dies, which it should (haven't
tested), I should be able to use IPC to do this through a Windows Service
that proxies and controls Windows process instances that get reset now and
then (depending on non-use or memory overload). IIS never gets unloaded but
now I'm dealing with parallel "cowboy processes".

Jon
May 4 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2213
by: Mickel Grönroos | last post by:
Hi, I'm trying to put an Tkinter.Entry of fixed size onto a specific location on a canvas using the place manager. The idea is that one can double-click a rectangle object on a canvas to get an entry field of the same size as the rectangle placed exactly over the rectangle thus creating the effect that the rectangle has entered "input mode". When clicking return in the entry field, the value is fed back to a text object within the...
1
3142
by: Mickel Grönroos | last post by:
Hi, I have a Tkinter.Canvas of variable width. Is there a standard way of asking the canvas which parts of it that is visible? I.e. on the horizontal scale, I would like to know at what fraction from the left the left visibility border is and from what fraction to the right the right visibility border is. Consider this ascii picture as an example
5
5592
by: Andrew Poulos | last post by:
Is there a right/best way to draw an ellipse using Canvas? (With VML there's the v:oval element which makes the exercise trivial). I tried drawing a 360 degree arc (a circle) and then scaling it but that also scales the thickness of the circumference. I'm trying bezier curves but without visual feedback it's pretty hard to draw. And quadratic beziers give, at least with the control points I can set, an oblate form. Whereas the only way I...
11
2094
by: Aaron Gray | last post by:
Hi, I have put together a bit of JavaScript to make a square resizable canvas :- http://www.aarongray.org/Test/JavaScript/resizable.html Problems I have :- a) I cannot seem to center it horrizontally b) It does not appear to be totaly square on either of my machines.
2
18302
TMS
by: TMS | last post by:
Schools over!!! Now its time to play. I would like to learn how to make objects move from one location to the next on a canvas widget. For example: from Tkinter import * class square: def __init__(self, canvas, xy, color, change): self.canvas = canvas self.id = self.canvas.create_rectangle(-10-abs(change),
6
3585
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from http://www.java2s.com/Code/Python/Event/Usemousetodrawashapeoncanvas.htm . The code itself is: from Tkinter import * trace = 0 class CanvasEventsDemo: def __init__(self, parent=None): canvas = Canvas(width=300, height=300, bg='beige') canvas.pack()
2
5692
by: devnew | last post by:
hi i am new to tkinter and would like some help with canvas i am doing validation of contents of a folder and need to show the ok/error messages on a canvas resultdisplay =Canvas(...) errmessage="error!" okmessage="dir validation ok!"
10
7377
by: blaine | last post by:
Hey everyone! I'm not very good with Tk, and I am using a very simple canvas to draw some pictures (this relates to that nokia screen emulator I had a post about a few days ago). Anyway, all is well, except one thing. When I am not in the program, and the program receives a draw command (from a FIFO pipe), the canvas does not refresh until I click into the program. How do I force it to refresh, or force the window to gain focus? It...
4
10101
by: moondaddy | last post by:
I have a wpf project where I use a canvas to drag shapes around. when I drag a shape beyond the right or bottom side I get scrollbars which is good. I also get scrollbars when I zoom in and a shape goes beyond the right or bottom side. However, I don't get scrollbars when shapes move beyond the left or top side of the canvas. This is bad. I need the behavior similar to Visio where you can drag an object past the left or top and you will...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.