|
A possible solution could be to have the VB application update a text / xml etc file, which would be polled by the c# console app to check if the user wants to take a snapshot. Maybe !
Everyone dies - but not everyone lives
|
|
|
|
|
if yes can you give me clear idea about that.
|
|
|
|
|
|
some of my classes implementing IDisposable, then it came up in my mind to test how the IDisposable works.
so i try this.
public class cc : IDisposable
{
bool isDisposed;
int[] sampleData;
public cc()
{
sampleData = new int[50000000];
}
~cc()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool isDisposing)
{
if (!isDisposed)
{
if (isDisposing)
{
sampleData = null;
}
}
isDisposed = true;
}
public void smp()
{
for (int i = 0; i < 50000000; i++)
{
sampleData[i] = i;
}
System.Threading.Thread.Sleep(20000);
Console.WriteLine("middle");
Console.ReadLine();
}
public void s2()
{
int[] ssss = new int[50000000];
for (int i = 0; i < 50000000; i++)
{
ssss[i] = i;
}
}
}
now creating the object and calling the smp() method, the program memory consumption increase about 100mb to 150mb then after the object was disposed, i was expecting that it will the memory it will consumed but even i leaved the program open for several minutes, still it doesn't release the memory.
why is that happen? i already try to test it in debug mode and check the sampleData variable after disposed it was NULL.
is there wrong it there?
BTW on the method s2(), does ssss will release the memory if the object is destroyed?
modified 9-May-14 7:11am.
|
|
|
|
|
It sounds like you have a slight problem with your understanding of how freeing up memory affects the memory allocated - there's no shame in that as it's not the most intuitive area. Basically, when you observe your .NET application running, the memory that you see is the memory that the .NET runtime has requested be allocated to run. Allocation of memory is a costly process, so the runtime grabs it in big chunks and doesn't necessarily release it when it has done a GC sweep. Simplistically, your application keeps a chunk of free memory available that it can grow into (in the same way that a serial dieter may keep old clothes that are several times larger just in case they put the weight on again). If the OS demands memory, your application will generally release this unallocated memory (equivalent to charity shops becoming really aggressive and coming round to your house and demanding old clothes).
|
|
|
|
|
So do you mean that even the object is already disposed, the memory it consumed will not decrease until the OS will demand it?
|
|
|
|
|
Or the .NET runtime decides it no longer needs it.
|
|
|
|
|
thank you very much,
one more question.
in the method s2()
public void s2()
{
int[] ssss = new int[50000000];
for (int i = 0; i < 50000000; i++)
{
ssss[i] = i;
}
}
i declared the variable "ssss" and it is not exposed out side of the method, what will happen to it if the object is disposed?
|
|
|
|
|
It gets freed. Anything that is no longer in scope or no longer has a reference to it gets freed/disposed.
|
|
|
|
|
thank you so much to all response, it help me to fully understand the IDisposable
|
|
|
|
|
I want to call a URL for a specified number of time even if there is a timeout exception or any other exception.
is there a method in c# which does this?
|
|
|
|
|
Just wrap the call in a loop and put the call itself inside a try/catch block.
|
|
|
|
|
I have to draw a rectangle using lines whose co-ordinates and measures are already provided.
In the below code, if I call CloseFigure function. C# assumes the drawing is incomplete and hence it draws an another line diagonally to close the rectangle.
If I use a AddRectangle function, the drawing is complete. No issues with that.
How can I complete a drawing, properly using lines?
private void OnPaint(object sender, PaintEventArgs e)
{
Pen redPen = new Pen(Color.Red, 2);
// Create a graphics path
GraphicsPath path = new GraphicsPath();
// Add two lines, a rectangle and an ellipse
Graphics g = e.Graphics;
path.StartFigure();
path.AddLine(20, 20, 20, 400); // left
path.AddLine(20, 20, 400, 20); //top
path.AddLine(400, 20, 400, 400); // right
path.AddLine(20, 400, 400, 400); // bottom
path.CloseFigure();
//This will close the drawing, by drawing a line between starting and ending point
}
|
|
|
|
|
Why do you use path.StartFigure() ? That's not needed.
|
|
|
|
|
You are creating a GraphicsPath, but that doesn't draw it, or indeed anything, until you use one of the Graphics.DrawXXX methods.
In your case, add this:
path.CloseFigure();
g.DrawPath(redPen, path);
} But do note that CloseFigure draws between teh first and last points - so you will get a diagonal as well!
Me? I'd draw your rectangle like this:
private void OnPaint(object sender, PaintEventArgs e)
{
using (Pen redPen = new Pen(Color.Red, 2))
{
Graphics g = e.Graphics;
g.DrawLine(redPen, 20, 20, 20, 400);
g.DrawLine(redPen, 20, 20, 400, 20);
g.DrawLine(redPen, 400, 20, 400, 400);
g.DrawLine(redPen, 20, 400, 400, 400);
}
} And save Paths and Regions for the more complex shapes!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi all, suppose I have a text file that contains hundreds of entries with each entry surrounded by an opening @ symbol and a closing /@ symbol, and each entry is separated from the next by a blank line like below:
@ Entry Date: 6/01/2014, Time:1000 AM EST, UserID: U123456789,
Input: Blah Blah Blah ggogo klj'm' lkkjhgy 8oiui9in lrxutxcuucx cufcfx rdutrrrd dxddzsz, /@
@ Entry Date: 7/01/2014, Time:1000 AM EST, UserID: U134233569,
Input: tgvggv jjjn tsewa klj'm' lkkjhgy ojgi yvytf j;jn ij[ji tfzdy , /@
If I want to get all the inputs of a particular user with a certain UserID, how would I go about doing that? I know I have to use string.contain method to check if a certain UserID exist and if it does, use the characters "@", "/@", "Input:", and "," as the delimiters to refine the search. But I'm not real clear on how to go about it. Any suggestions will be greatly appreciated, thanks in advance.
|
|
|
|
|
I would create an object that will hold all the bits of your info,
Depending on the size of the file I would either read it all into memory or read it 1 line at a time.
If the line starts with your open token @ set a flag, keep reading till your line ends with your end token /@, appending the line(s) to a string variable.
Depending on your structure I would then pass the string variable to a parser which chops up the crap you are getting for data, it looks like the start of the record is reasonable and it deteriorates into rubbish with no structure.
The parser should return an instance of the object which is then added to a List<>.
Repeat until you get to the end of the file.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm with Mycroft Holmes.
You need an object eg Entry with several properties:
* entrydate
* userid
* input
* ...
Then read in the file. You have several options: read line per line or in one piece and then split.
If there are more then one message per userid you can more cleverly make a dictionary holding all the data for that user...
Hope this gives you some ideas.
|
|
|
|
|
First get all matches between @ and /@ tags,
then write a method which takes a single block and returns UserID (you can do it by indexof and substring methods)
then iterate all matches and take appropriate ids.
So;
MatchCollection matchList = Regex.Matches(yourInput, yourPattern);
var list = matchList.Cast<Match>().Select(match => match.Value).ToList();
var result = list.Where(p=> GetUserID(p) == "XXXXX").ToList();
private string GetUserID(string singleBlock)
{
Extract user id and return it;
}
Tim Toady Bicarbonate
|
|
|
|
|
I have an .Net 4.0 app that runs processes at specified intervals. My code uses reflection to run the process:
private static void executeProccess(ProcessEntity process)
{
_ProcessBase instance = null;
try
{
Assembly assembly = Assembly.LoadFrom(process.AssemblyName);
Type type = assembly.GetType(process.TypeName);
instance = (_ProcessBase)Activator.CreateInstance(type);
}
catch (Exception e)
{
LogMessage(e);
}
if (instance != null)
{
LogMessage(string.Format("Starting process '{0}'", process.Caption));
var task = Task.Factory.StartNew<ProcessResponseEntity>(() => instance.Execute())
.ContinueWith(x => processCompleted(x.Result));
task.ContinueWith(ExceptionHandler, TaskContinuationOptions.OnlyOnFaulted);
task.Wait(1000);
}
}
private static void ExceptionHandler(Task task)
{
var exception = task.Exception;
Console.WriteLine(exception);
}
I can't see to get the exception handing code to work right. Is this the right way to do this?
If it's not broken, fix it until it is
|
|
|
|
|
Hello
Here is a free .NET obfuscator, I've created it to use for my own projects.
What it currently can do: rename types and remove namespaces, rename methods and fields, remove properties and events declarations, rename (private) assembly files. Basically, my primary goal was to make it remove all meaningful information that can help reverse engineers to analyze the program.
It provides 2 features, that I needed and couldn't find in existing products:
1. Flexible settings system that allows fine-grained control over classes and members obfuscation parameters.
2. It can obfuscate public types and members (useful for assemblies that are not exposed outside of your program)
Looking forward to your feedback.
|
|
|
|
|
Write an article about it and you'll get the feedback you desire. This is not the right place to post this, otherwise.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Well, I wasn't sure if it's allowed.
I promise to write an article, but the project is not mature enough (yet).
|
|
|
|
|
ianderf wrote: the project is not mature enough (yet). Then it's too early for people to review it.
|
|
|
|
|
Hi guys,
I've been working on a custom component which acts as a 'view' control, such that it manually paints cells for child items. The component can contain hundreds of child items, which means that I've had to utilise the BufferedGraphics object for maintaining the graphics, and reset it only when the component is resized or when the child items are changed. Each child items also owns it's own BufferedGraphics object to maintain the rendering of each item (since these items can contain an Image in the graphics, it speeds up the painting considerably.)
A problem surfaces when I start to take into account scrolling through the use of AutoScroll and AutoScrollPosition . I've spent a good while trying to search for an answer to applying the scroll position offset to a BufferedGraphics and I've yet yielded unsuccessful results. Several problems are standing in the way of the scrolling functionality:
1. Graphics.TranslateTransform() or Graphics.Transform = new Matrix() does not translate a BufferedGraphics.Render() operation. I believe this is namely because the Render() function just paints directly onto the Graphics handle for the region it was allocated by.
For example, the below does not work:
override void OnPaint(PaintEventArgs e)
{
e.Graphics.TranslateTransform(-AutoScrollPosition.X, -AutoScrollPosition.Y);
this.bufferedGraphics.Render(e.Graphics);
}
2. Following the code in this example [^] results in many invalidations, which causes the graphics to lag to the point that it's infeasible for the component.
My question is, is there a reliable method of being able to translate the buffered graphics of a BufferedGraphics object when painting onto a Graphics handle? For instance, could I allocate my BufferedGraphics as I do in point #1, and intrinsically invalidate the component upon scrolling and simply offset the buffered graphics depending on the position the user has scrolled to?
If not, can anyone recommend a suitable replacement for rendering like this? Obviously, components such as the ListView class have the ability to render many items with scrolling, with little issues with performance (depending on which double-buffering and CreateParams changes are made.)
|
|
|
|
|