|
There is no one function to call to find this out. Since the .NET Framework reserves a chunk of memory for your application, using the normal non-.NET methods (like Task Manager) of memory size won't work.
In order to get the real numbers, you'll have to query the .NET CLR Memory performance counters. These are the very same counters you'll find in the Administrative Tools/Performance Monitor tool.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
C# - We are using a large, common set of images for buttons in our application, across a large number of forms - this is a very large app. I'm exploring using a dll with 1) an imagelist which can be accessed by any screen needing it, or else 2) embedded .gif resources that are then accessed via a static method in that dll.
Either way, it would be nice to be able to add something to the Visual Studio ToolBox so that when developers design their screens, they can assign images to controls and actually see them in the designer.
Can anyone point me in the right direction for info on accomplishing this?
Thanks
Rich
ps - remove the x from the email address if you wish to contact me directly.
|
|
|
|
|
Without giving it too much thought ...
one approach you could take is to place your images in an imagelist that is held in a static class. The forms just need reference to the DLL and they can call a static method that you would have to write :
Image GetImage(int imageNumber);
GetImage() would return the image in the imagelist at the specified location. The apps would have to set their icons at initialization time for buttons, etc.
That would have to be a very-well protected DLL though since changing the image locations would screw the entire application.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Thanks for the reply. If I do use a statically created ImageList, would I be able to access it from the toolbox in design mode, so that the other programmers could use that imagelist in their individual forms?
|
|
|
|
|
That's the downside to the design. To have something at design time, you need to have every form have the imagelist within themselves. This makes a maintanance issue for large projects like yours.
By keeping a atatic list accessed with a static method, you centralize support, but eliminate the convenience of design time deployment. That is why I said you would need a standard that developers initialize their images at constructor time. But you could take the list of images, create a graphic cheat sheet in Paint with their numbers in the imagelist and distribute that. Then when they create the constructor code they can visually see the graphics so they know they are mapping the correct image to the control by the method call.
On the bright side: after one or two forms are built, the developers can get accustomed to this way of setting graphics rather quickly.
If your forms have some standard graphics/buttons on all forms, you could also establish the graphics and image initialization and use that as an inherited form. That reduces the amount of development for the image management and increases standardization.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I have ListView control in Details view, and i want to show an icon to each item in the first column. Is it possible in this details view of the control?
thanks.
|
|
|
|
|
Set the imageindex of the listview first. Keep the listviewItem.SubItems[0].Text = "".
Then do something similar to following.
foreach ( ListViewItem item in this.Items )
{
if ( ((EntityBase)item.Tag).ValueList["CloseDate"].ToString().Trim() == String.Empty )
{
item.ImageIndex = OPEN_INDEX;
}
else
{
item.ImageIndex = CLOSE_INDEX;
}
}
Alomgir Miah
Live Life King Size
|
|
|
|
|
How can i check when the user starts my software that it is already opened and do something like a messageBox, and if not opened start it normally
kevin smoke
|
|
|
|
|
|
Hi!
How can we code to make assure that if the thread we want to abort is processing a function, it just be aborted after finish that function ?
Thanks!
|
|
|
|
|
Here is one way of stopping your thread, making sure your current execution ends and you do not get an AbortException. You would have something like this to establish the thread in your main processor:
ThreadClass function = new ThreadClass();
myThread = new ThreadStart(function.Process);
your Process would be something like this:
public bool ThreadWanted = true;
... init/constructor logic ...
do
{
if ( ..no data to process.. )
Thread.Sleep(50);
...function
}
while (ThreadWanted)
return;
when you want the thread to abort just do this in the thread creator logic:
public void TerminateProcess()
{
function.ThreadWanted = false;
}
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Hi!
Thanks a lot!
|
|
|
|
|
You need to declare the bool variable with the volatile qualifier, without it, there is no guarantee that setting it to true would immediately reflect in the other thread.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Well i got problem, i have in form the panel, where i draw shapes, and a treeview where i insert the data about shapes I want to do it in two different threads, but how to do it? I explaine my architecture:
I got a class TOC derived from treeview, and i got a mapcontrol derived from panel, and i have maptable - array of objects. So, when i add new object in the maptable i update data in two components - mapcontrol and TOC... All the objects linked to each other (by references). If it's possible without having static variables?
|
|
|
|
|
Any time you have a process using Forms, you will have issues when dealing with more than one thread. But what you describe sounds like you need to consider implementing the Model, View, Controller pattern to solve your problem.
In the MVC pattern, your various elements on your form are Views of data. The Model handles read/update of data and implements an Observer pattern. The Views are subscribers to the Observer.
The controller creates the Views, tells them their states, and receives events that represent User Gestures. So when a 'user gesture' occurs that changes data in your TOC (for example) the controller notifies the Model what that change is (maybe by something like model.StateChange(chapterChosen)).
The model gets that particular chapter object, and raises the Observer event. The Views receive the event and read the data specific to each view from the Model. Thus you change one control and all of the controls automatically change.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Yes , this is the way i saw, but...
Your next words:
"The Views receive the event and read the data specific to each view from the Model"
How can views read the data of another class (controller)? Because when i make the thread i can read only static members...
Maybe little example could help me... Maybe i don't understand you...
|
|
|
|
|
Many of the Patterns websites discusses MVC...but an example is a Form with two temperature boxes -- one 'view' displays Fahrenheit and the other 'view' displays Celcius.
The controller creates each view:
TempView fView = new TempView(TempState.Fahrenheit);
TempView cView = new TempView(TempState.Celcius);
myForm.FTempPanel.Controls.Add(fView));
myForm.CTempPanel.Controls.Add(cView);
the controller then gets the model:
Model mymodel = new Model();
The controller then passes the IObservable data to each view
fView.SetObserver(mymodel.GetObserver);
cView.SetObserver(mymodel.GetObserver);
Finally controller wants a starting temperature to display. I'd normally get it from a saved control file but for this example it is hard coded {shudder}:
mymodel.SetTemp(75);
Now...when the views got the observer interface, they used that to register:
public void SetObserver(IObservable myObserver)
{
myObserver.DataChangeEvent += new DataChangeHandler(newTemp);
}
when the model gets called with SetTemp() the model notifies the observers that there is new data:
public void SetTemp(int temperature)
{
mytemp = temperature;
ChangeEventArgs myargs = new ChangeEventArgs("temp");
if (DataChangeEvent != null)
DataChangeEvent(this, myargs);
}
Now -- the model DataChangeEvent is happening inside the message pump thread. As a result your form can deal with the event and change the form without having the message pump get confused. So in your TempView object you have an event handler that just says:
public void newTemp(object sender, ChangeEventArgs args)
{
if (args.ChangeType == "temp")
this.temperature.Text = myObserver.GetTemperature(myState).ToString();
}
So the view recognized that the change was one that affected itself, it made a call into the model (readonly!!!!) to get the temperature and the model used the state to return the correct value of Fahrenheit or Celcius.
Now if you add a slider to the form (which is your TOC) and that is a view that changes temperature, it's only job is to talk to the controller. If the slider is moved, the end result is passed to the controller as a user gesture:
IN THE CONTROLLER
... TempSlider slider = new TempSlider();
slider.SetUserChangesTempEvent(new EventHandler(ChangeTemp);
myForm.SliderPanel.Controls.Add(slider);
and in the slider...
public class TempSlider
{
...
public void Slider_ValueChange()
{
.. after validating the input to verify it is correct
TempArgs args = new TempArgs(slider.Value.ToString);
if (UserHasChangeTempEvent != null)
UserHasChangeTempEvent(this, args);
}
finally the controller gets the changed temp event, calls the model with the new value, and the model notifies the observers who change to the new value.
It is more complex but you can quickly see that your views are completely free from the form, placement on the form, and from the data. Events happen within the Apartment Thread and the forms get updated without impact to the forms, the message pump, etc. To have an independant thread run, the changed data is just one more UserGesture inside of your control. I tend to encapsulate the Event registration in a method call in case I want to do anything fancy or have multiple event registrations respond to the same eventhandler.
Hope this helps. Google Model View Controller Pattern to find out more.
|
|
|
|
|
For example here is my code:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace GeoObjects
{
public class GeoTOC : System.Windows.Forms.TreeView
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ImageList imageList_LayersColor;
GeoMapControl m_pGeoMapControl;
public GeoTOC()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.imageList_LayersColor = new System.Windows.Forms.ImageList(this.components);
this.imageList_LayersColor.ImageSize = new System.Drawing.Size(16, 16);
this.imageList_LayersColor.TransparentColor = System.Drawing.Color.Transparent;
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.CheckBoxes = true;
this.ImageIndex = 0;
this.ImageList = this.imageList_LayersColor;
this.SelectedImageIndex = 0;
}
#region Accessors
public GeoMapControl MapControl
{
set
{
m_pGeoMapControl = value;
m_pGeoMapControl.TOC = this;
}
}
#endregion
public void UpdateTable()
{
this.BeginUpdate();
Nodes.Clear();
imageList_LayersColor.Images.Clear();
System.Drawing.Bitmap img = new System.Drawing.Bitmap(16,16);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
g.Dispose();
imageList_LayersColor.Images.Add(img);
foreach(GeoMapTable gmt in m_pGeoMapControl.MapTables)
{
TreeNode Map = Nodes.Add(gmt.Name);
Map.Checked = gmt.Visible;
Map.ForeColor = Color.Blue;
foreach(GeoLayer gl in gmt.Layers)
{
img = new System.Drawing.Bitmap(16,16);
g = Graphics.FromImage(img);
g.Clear(Color.White);
g.FillRectangle(new SolidBrush(gl.LayerColor),3,3,11,11);
g.Dispose();
imageList_LayersColor.Images.Add(img);
TreeNode layer = Map.Nodes.Add(gl.Name);
layer.Checked = gl.Visible;
layer.ImageIndex = imageList_LayersColor.Images.Count-1;
layer.SelectedImageIndex = imageList_LayersColor.Images.Count-1;
}
}
this.EndUpdate();
}
protected override void OnAfterCheck(TreeViewEventArgs e)
{
TreeNode parent = e.Node.Parent;
if(parent==null)
((GeoMapTable)m_pGeoMapControl.MapTables[e.Node.Index]).Visible = e.Node.Checked;
else
((GeoLayer)((GeoMapTable)m_pGeoMapControl.MapTables[parent.Index]).Layers[e.Node.Index]).Visible = e.Node.Checked;
m_pGeoMapControl.PaintMap();
base.OnAfterCheck (e);
}
}
}
How can i make the method UpdateTable() in the thread???
|
|
|
|
|
I tried next, and got next error message :An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: The action being performed on this control is being called from the wrong thread. You must marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action.:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
namespace GeoObjects
{
class FillIn
{
static GeoObjects.GeoTOC m_pGeoTOC;
public FillIn(GeoTOC toc)
{
m_pGeoTOC = toc;
}
public static void Process()
{
m_pGeoTOC.UpdateTableThread();
}
}
public class GeoTOC : System.Windows.Forms.TreeView
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ImageList imageList_LayersColor;
GeoMapControl m_pGeoMapControl;
public GeoTOC()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.imageList_LayersColor = new System.Windows.Forms.ImageList(this.components);
this.imageList_LayersColor.ImageSize = new System.Drawing.Size(16, 16);
this.imageList_LayersColor.TransparentColor = System.Drawing.Color.Transparent;
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.CheckBoxes = true;
this.ImageIndex = 0;
this.ImageList = this.imageList_LayersColor;
this.SelectedImageIndex = 0;
}
#region Accessors
public GeoMapControl MapControl
{
set
{
m_pGeoMapControl = value;
m_pGeoMapControl.TOC = this;
}
}
#endregion
public void UpdateTableThread()
{
this.BeginUpdate();
Nodes.Clear();
imageList_LayersColor.Images.Clear();
System.Drawing.Bitmap img = new System.Drawing.Bitmap(16,16);
Graphics g = Graphics.FromImage(img);
g.Clear(Color.White);
g.Dispose();
imageList_LayersColor.Images.Add(img);
foreach(GeoMapTable gmt in m_pGeoMapControl.MapTables)
{
TreeNode Map = Nodes.Add(gmt.Name);
Map.Checked = gmt.Visible;
Map.ForeColor = Color.Blue;
foreach(GeoLayer gl in gmt.Layers)
{
img = new System.Drawing.Bitmap(16,16);
g = Graphics.FromImage(img);
g.Clear(Color.White);
g.FillRectangle(new SolidBrush(gl.LayerColor),3,3,11,11);
g.Dispose();
imageList_LayersColor.Images.Add(img);
TreeNode layer = Map.Nodes.Add(gl.Name);
layer.Checked = gl.Visible;
layer.ImageIndex = imageList_LayersColor.Images.Count-1;
layer.SelectedImageIndex = imageList_LayersColor.Images.Count-1;
}
}
this.EndUpdate();
}
public void UpdateTable()
{
FillIn fi = new FillIn(this);
Thread mythread = new Thread(new ThreadStart(FillIn.Process));
mythread.Start();
}
protected override void OnAfterCheck(TreeViewEventArgs e)
{
TreeNode parent = e.Node.Parent;
if(parent==null)
((GeoMapTable)m_pGeoMapControl.MapTables[e.Node.Index]).Visible = e.Node.Checked;
else
((GeoLayer)((GeoMapTable)m_pGeoMapControl.MapTables[parent.Index]).Layers[e.Node.Index]).Visible = e.Node.Checked;
m_pGeoMapControl.PaintMap();
base.OnAfterCheck (e);
}
}
}
|
|
|
|
|
Hi guys,
Pls Could someone help/ tell me how to create a gif file in c# .net as i cant find anything on the subbject.
I basically need to be able to create a gif animation from a series of jpg files,
Any help, ie books, websites, articles anything that you might think will help me pls let me know as i am out of ideas.
Thanks
|
|
|
|
|
Strip Images From Animated Gif:
http://www.eggheadcafe.com/articles/stripimagefromanimatedgif.asp
...these actions in reverse may work
P.S. Google: 'c# gif'
|
|
|
|
|
thanks for that i will have a go at doing it, pls let me know if you think of anything else which might help.
Thanks
|
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
this one is nice, that explain how to make a palette.
PS: the transparence doesn't work you must patch it.
|
|
|
|
|
thanks ive had a look at that already, if there is anything else you guys can give then pls do,
btw i want to do this in c# i dont want to use adobe or anything else.
|
|
|
|