|
Ok ! Super ! Super !
Thank you very much , it works well as expected !
|
|
|
|
|
I've seen examples like this a number of times, but why not just use the owner property of the child form when you create it? - this would save creating a new form object in each child form, especially when it has the right property sitting there waiting to be used.
you can access it by
Form2 frm=new Form2();
frm.Owner = this;
then in the child form you can access this by
((Form1)Owner).publicproperty = value;
a bit more typing but keeps overheads down I would assume.
|
|
|
|
|
I have a strange problem related to ever rising memory in the GC heaps. When
I run my service, memory is continually allocated during a test cycle.
However if I simply change the services startup routine to instead just wait
showing a messagebox (instead of adding the service) and let the other
threads carry on their work I get a nice zig-zag line as expected in perfmon
showing #Bytes in all Heaps which always stays under #Total committed
Bytes. The graph for the service version just increases upward for both
counters. What could be happening?
I understand that the GC only collects memory if it has to, and is only does
this during further allocations but I want to prevent my service claim more
resources than is needs to run preventing other NON .NET application being
starved of RAM.
|
|
|
|
|
solidstore wrote:
I understand that the GC only collects memory if it has to, and is only does
this during further allocations but I want to prevent my service claim more
resources than is needs to run preventing other NON .NET application being
starved of RAM.
What memory intense objects are you creating? Perhaps implementing them as a static object will not require it to be created everytime, and does it need to be created for every call or does the object prefer to stay "persistant" across web service calls?
You will have to supply some more info if you want someone to give you a better answer.
<a TITLE="See my user info" href=http:
|
|
|
|
|
Basically I have a Windows Service which is hosting some Remotable objects. These objects are also registered with COM.
Our test client in an ASP code which creates the COM objects. This activate the real .NET object inside my C# service. Everything work fine, except that memory allocs continue endlessly.
In desperation I changed the service to run as a standard process whilst I was debugging. Now memory is being correctly garbage collected. I'm using the perfmon counter to view the zig-zag profile.
Memory only increase when the code is run as a Service. I just have to replace the ServiceBase.Run method call with a long Sleep. To make my test run behave VERY differently.
The objects I'm creating for each test call are very small & stateless. They return a small string ("foo") from they only method call.
The ASP code sets the object to Nothing after the call. I'm assuming releasing the COM object, releases the CCW, which release the remote server object.
|
|
|
|
|
solidstore wrote:
Memory only increase when the code is run as a Service. I just have to replace the ServiceBase.Run method call with a long Sleep. To make my test run behave VERY differently.
The objects I'm creating for each test call are very small & stateless. They return a small string ("foo") from they only method call.
From what you're saying, it seems to be a bug in the .NET framework. Your ASP page hasn't changed, only the server is changing, but the components are no being released anymore. Are they MarshalByValue or MarshalByRef objects?
Depending on what you're doing, as a workaround, I suggest you to derive your classes from ServicedComponent and run them from inside a COM+ application, and export the application proxy, so the ASP page could call your components.
I use it all the time and it's very stable.
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
My remote objects derive from MarshalByRefObject and their custom COM interface. I read in a newsgroup somewhere that if you derive from this class you must call System.Runtime.Remoting.RemotingServices.Disconnect. But from where?
How simple is hosting inside COM+? I'm meant to ship this week!
Could anyone else confirm this is a bug in .NET? You only need a small application to test this I guess.
|
|
|
|
|
solidstore wrote:
How simple is hosting inside COM+? I'm meant to ship this week!
It will take you only a few minutes. For trivial objects, it's just a matter of deriving from ServicedComponent (which is indeed derived from MarshalByRefObject), put some attributes on the assembly describing the package name, and some simple configurations, and then, running regasm to put your assembly under COM+.
And you'll need to remove all your service code, COM+ will take care of this for you.
solidstore wrote:
Could anyone else confirm this is a bug in .NET? You only need a small application to test this I guess.
This raises me another (I know, obvious) question: are you with 1.1 framework? 1.0 with all SP applied?
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
I'm using 1.0 framework with SP2. With less than a week to go v1.1 seems a bit risky + we have lots of other apps on v1.0 that need to ship together. I'm developing & testing on XP pro but we deploy onto Win2K advanced servers. Fully patched & serviced packed in both cases.
|
|
|
|
|
I'm using 1.0 framework with SP2. With less than a week to go v1.1 seems a bit risky + we have lots of other apps on v1.0 that need to ship together. I'm developing & testing on XP pro but we deploy onto Win2K advanced servers. Fully patched & serviced packed in both cases.
I've also made an interesting discovery:
I've downloaded the SciTech memory profiler which I've attached to the Service. Things continue to leak as usually during the test, however after I create the first snapshot, it seems to start garbage collecting correctly!!!! I dont know what the profiler does but you can see that is makes some forced GCs which kick things into action. I've tried to do this myself in code by forcing collection but it didnt work. What could be causing things to suddenly work when the profiler first does something?
|
|
|
|
|
solidstore wrote:
I've downloaded the SciTech memory profiler which I've attached to the Service. Things continue to leak as usually during the test, however after I create the first snapshot, it seems to start garbage collecting correctly!!!! I dont know what the profiler does but you can see that is makes some forced GCs which kick things into action. I've tried to do this myself in code by forcing collection but it didnt work. What could be causing things to suddenly work when the profiler first does something?
Forcing collection doesn't work? Strange. It seems that you have some form of dangling pointers. You've said you are mixing remoting + COM. Can you isolate one of them, like, creating a "pure" remoting client and a "pure" COM client, to see where is the problem, or if the problem comes with mixing them?
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
good idea! do you mean create a C# exe to test the Remoting by creating the objects natively? And create another C++ client to create the COM objects but without setting up the remoting configuration?
Other tests just in:
I've just tried make my service run under my local administrator account (instead of SYSTEM) and the memory performance counters appear normal (although my process no longer show up in the perfmon list - I'm having to use _Global_).
Could the user account being used affect GC?
Why has my process/service disappeared from perfmon now I've changed the user account?
|
|
|
|
|
|
Also is Remoting and COM Interop OK with the same object? Or should I create one object thats exposed to COM which internally calls my remote component?
|
|
|
|
|
Are you using COM objects in your service, like ADO recordsets?
They can be a big source for memory leaks, because all the GC can see is the managed allocated memory, which is small, basically a pointer to a small wrapper. But, on the side of the COM object, it may be taking several MB of RAM.
So, to assure a COM object is correctly garbage collected, you need to call System.Runtime.Interop.Marshal.ReleaseComObject on a loop until it returns 0.
Another common source for memory leaks under a GC environment is forgetting to call Dispose on the IDisposable objects.
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
see reply to leppie above - many thanks
|
|
|
|
|
When our code is running as a normal C# process, garbage collect can be seen
working using perfmon during a test. Running the same code but as a service,
garbage collection does not appear to kick in? However when attaching the
Memory Profiler the service returns to expected garbage collection as viewed
from perfmon.
What could cause my code running as a process (and profiled service) to have
a nice shallow zig-zag perfmon trace of #bytes in heap. Yet when its run as
a service the #bytes in heap rises very steeply indeed and no sign of the
garbage collector's zig-zag?
The code is fully managed and I'm not using any COM objects. I am exposing object within my assembly to COM and via Remoting
|
|
|
|
|
Hi, I was wondering if anyone knew about a grid for windows forms that could do the following
I want that the user enters a value in the grid and that for every value he enters appears a combo box in the cell next to the value he entered
There is no data binding, the user manually has to enter a value, and for each value there has to be a combo box next to it from which he can make a selection
Then I can iterate through the grid and get what he typed and selected
Thanks in advance
|
|
|
|
|
You can use the SourceGrid that is available on this site. It provides the functionality that you have requested and isn't data bound.
|
|
|
|
|
Hey,
Ive been writing a simple image viewer program in C# and wanted to add the option to save a loaded image to another format. In the tiff format though its been a pain, i want to read in the tiff image's format, and give the option of changing that format. So far i do not know how to read an images properties, can anyone help?
Heres the proto source code ive done (bulit up mostly from CodeProject articles )
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ImageViewer
{
public class MyForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
protected MenuItem _itemNativeSize;
protected MenuItem _itemWindowSize;
protected int _filterIndex = -1;
protected Bitmap _myBitmap;
protected bool _nativeSize = true;
public MyForm()
{
InitializeComponent();
// set the initial text and size of the window
this.Text = "Image Viewer 0.0";
this.ClientSize = new Size(640, 480);
....
}
private void OnOpenImage(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if(_filterIndex != -1)
ofd.FilterIndex = _filterIndex;
if(ofd.ShowDialog() == DialogResult.OK)
{
String filename = ofd.FileName;
if(filename.Length != 0)
{
_filterIndex = ofd.FilterIndex;
try
{
_myBitmap = new Bitmap(filename);
this.Text = "Image Viewer - " + filename;
this.AutoScroll = true;
this.AutoScrollMinSize = _myBitmap.Size;
this.Invalidate();
}
catch
{
MessageBox.Show(String.Format ("{0} is not " +
"a valid image file", filename), "Error");
}
}
}
}
private void OnSaveImage(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Save Image As";
if(sfd.ShowDialog() == DialogResult.OK)
{
sfd.AddExtension = true;
String filename = sfd.FileName;
if(filename.EndsWith(".png"))
_myBitmap.Save(filename, ImageFormat.Png);
else if(filename.EndsWith(".tiff") || filename.EndsWith(".tif"))
_myBitmap.Save(filename, ImageFormat.Tiff);
else if(filename.EndsWith(".bmp"))
_myBitmap.Save(filename, ImageFormat.Tiff);
else if(filename.EndsWith(".jpeg") || filename.EndsWith(".jpg"))
_myBitmap.Save(filename, ImageFormat.Jpeg);
else if(filename.EndsWith(".gif"))
_myBitmap.Save(filename, ImageFormat.Gif);
else
MessageBox.Show("Unknown file type");
}
}
private void OnExit(object sender, EventArgs e)
{
this.Close();
}
protected override void OnPaint(PaintEventArgs e)
{
if(_myBitmap != null)
{
Graphics g = e.Graphics;
if(_nativeSize)
{
g.DrawImage(_myBitmap,
this.AutoScrollPosition.X,
this.AutoScrollPosition.Y,
_myBitmap.Width, _myBitmap.Height);
}
else
{
g.DrawImage(_myBitmap, this.ClientRectangle);
}
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new MyForm());
}
}
}
|
|
|
|
|
Hey All,
I have been printing to a Zebra barcode printer previously in vb6. I was able to print just a test line of text by using something similar to the following,
printer.print "This is a test"
I am trying the same little test using cSharp with this statement,
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, 0, 0);
This being an event that is called when my printPage_PrintDoc event is being fired. The printer seems to recognize that it is receiving text, and then just prints out a blank label. I even checked the ribben to ensure that its just not printing off of the label somewhere, as if I had bad x,y coordinates. Any suggestions would be greatly appreciated.
Thanks,
Ryan
|
|
|
|
|
Curious how a person would go about adding Visual Inheritance _after_ you have already created the forms. I am currently working on an MDI application and I decided to use VI on the majority of those forms.
Is there a way to add the inheritance after the fact ?
Rocky Moore <><
|
|
|
|
|
WinForms inherit from From as shown in top of your class' source code...
public class frmAbout : System.Windows.Forms.Form
Just make yourself another form (your new base form, somewhere down the line inheriting from System.Windows.Forms.Form) and replace the inheritance in your existing class.
It should look something like this:
public class MyNewBaseForm : System.Windows.Forms.Form<br />
{<br />
}
and
public class frmAbout : MyNewBaseForm
Should come up in the visual designer too...
|
|
|
|
|
Arjan Einbu wrote:
Should come up in the visual designer too...
Didn't come up nor at runtime. That is why I asked, trying to figure out what is missing. I even tried closing out all designers and closing VS.NET then reloading. Still no go.
Rocky Moore <><
|
|
|
|
|
Arjan Einbu wrote:
Should come up in the visual designer too...
For some reason, when I copied the project to another directory it lost the background image settings and the buttons on the form to be inherited happend to be off the view of the form. When I would run the application it did not show the background nor the buttons (since they were clipped). The designer still showed everything proper for the base window until today when I booted the system and went into the designer.
Anyway, now works as I thought it would have the first time.
Rocky Moore <><
|
|
|
|