|
With that sequence of operations, I could explain if and only if the two destination files are the same.
(you didn't show the calls to ecrireFichier and ecrireTraduction)
Suggestions:
1. check your code, make sure both sNomFichier values are different;
2. insert a Thread.Sleep(5000) before opening the second file.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The only difference in the names is the extension. And the exception shows the name of the second file (with .rak extension).
I tried with Thread.Sleep(5000); it freezes well for 5 seconds, but the exception is still here !
The only way I found to bypass this exception is, before calling the ecrireTraduction function, to delete the file :
FileInfo fInfo = new FileInfo(sFichierTemp);
if (!fInfo.IsReadOnly)
{
fInfo.Delete();
}
The STRANGE thing is that it can't be opened for writing for overwrite, but it's ok for open for append or delete the file !
|
|
|
|
|
why the IsReadOnly check?
are you playing with the file properties? if so, you should have said so from the start!
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I found !!
After writing the data file 2 for the first time, I set its Hidden property to true; The goal was to make things transparent to the user.
If I remove this attribute to the file, and try to write it, it works ! I've never heard of such behaviour ...
Thanks a lot for your help about that !
|
|
|
|
|
good.
Are you running on a Virtual Machine? which one?
and which Operating System?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
No it's not in a virtual machine.
I tried it both on XP and Seven RC, and it's ok now !
|
|
|
|
|
Thanks for your help,
there is something even more strange : before opening the StreamWriter that throws the exception, if I try to delete the file, there's no error. It can be deleted, but can't be opened for writing.
|
|
|
|
|
Member 4052498 wrote: It can be deleted, but can't be opened for writing.
That doesn't make sense to me.
If that's correct, I would say something is very wrong.
I suggest you delete the file, reboot the system, rebuild the app, and try again.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I'm a newbie in computer programming so please have this in mind.
I have a class called Pinger which does basic pinging of hosts on a network. I'm currently implementing a network scanner so I create an array (254) of Pinger's. The problem occurs when I try to dispose the array after I've done the scan. I dispose every Pinger in the array - the Pinger class contains Dispose methods (GC.SuppressFinalize).
Still, the array of Pinger's still uses a lot of rescources on my system and I can clearly see the memory beeing freed when I close my application.
Does anyone have any idea on how to correctly get rid of the rescources being used (after I'm finished using them)?
I have the complete project, but couldn't find a way to upload it so if anyone want's to see it let me know how I can send you the project.....
private void AllPingsFinished()
{
counterForInsert = 0;
foreach (Pinger str in _pinger)
{
if (str != null)
{
str.Dispose();
}
}
}pre>
|
|
|
|
|
I don't think that you can remove object from Collection while it's looping
In Other word
<br />
<br />
foreach ( string str in MyList)<br />
{<br />
MyList.remove(str);<br />
}
List<string> ListForDetele = new List<string>();<br />
foreach (string str in MyList)<br />
{<br />
ListForDelete.Add(str);<br />
}<br />
<br />
foreach(string str in ListForDelete)<br />
{<br />
MyList.Remove(str);<br />
}
Have a good day ,
I know nothing , I know nothing ...
|
|
|
|
|
I will try this!
Thanks!!
|
|
|
|
|
Hi,
it is wise to call Dispose() on an object you no longer need, so it can release its unmanaged resources in a deterministic way. However that does not take care of the managed resources, i.e. the object is still alive (as your array is alive and holds a reference to it).
e.g. if each Pinger holds a thread, then that thread (and its stack memory) are still allocated (unless you cleaned them too in Dispose).
so it would also be good to remove the reference from the array as soon as you don't need them.
Kaare Tragethon wrote: I can clearly see
do you? how? Task Manager is not the right place to get accurate information on this subject. It shows the
working set, not how much memory the app NEEDS.
The differences are:
- the app may need to hold that amount of data;
- or the app may have asked that amount of memory because that was the fastest way to get things done, but in reality lots of memory are unused INSIDE the app (instead of inside the Window memory pool).
Test: minimize your main form. Does that dratically reduce the "memory requirement"? if yes, point proven.
More comments:
- why do you need 254 Pingers all at once? do they really all work in parallel? do you have that many threads?
AFAIK TCP/IP will choke. I tend to use say 8 threads and let each of them ping the addresses one after another (one job list, each thread picks the next job in turn).
- I tend to use a plural noun for a collection, so I would write foreach(Pinger pinger in pingers)...
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks a LOT to both of you!
I will definetively try a combination of both your answers (max 8 pingers, and add them to a list)!
Best regards
|
|
|
|
|
Hi , have a good day
I have the Class
class MyClass
{
private int _myvar;
public int MyVar
{
get
{
return _myvar;
}
set
{
_myvar = value;
}
}
public void ChangeMyVar(int NewValue)
{
_myvar = NewValue;
MyVar = NewValue;
}
}
Which method is the standard One ?
Method 1 , or Method 2 ?
thank you
I know nothing , I know nothing ...
|
|
|
|
|
Why would you need ChangeMyVar(int) if you have your public int MyVar property? That would be used to interface with the private _myvar, you woulnd't need the method ChangeMyVar(int).
|
|
|
|
|
Thank you for your replay ...
I made a simple DAL class , and it's used to Change the myvar variable inside it's Class
I know nothing , I know nothing ...
|
|
|
|
|
Stark DaFixzer wrote: Which method is the standard One ?
It depends. Like most things in programming.
Suppose that your code looked like this:
class MyClass
{
private int _myvar;
public int MyVar
{
get
{
return _myvar;
}
set
{
_myvar = value;
GoOffAndDoSomethingThatIsDoneWhenMyVarChanges(value);
}
}
public void ChangeMyVar(int NewValue)
{
_myvar = NewValue;
MyVar = NewValue;
}
GoOffAndDoSomethingThatIsDoneWhenMyVarChanges(int newValue)
{
}
}
Which method you use from within the class would depend on whether you wanted the 'side effect' to happen ('side effects' are usually, though not always, events).
From outside the class there is no choice you must use Method2.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you , that is exactly what I need to understand ....
I know nothing , I know nothing ...
|
|
|
|
|
So I hope this has a Simple answer.
I have a program with 6 Options, they can be either RadioButtons or CheckBoxs, But I need to know how to limit the options to 3 or less?
Is there an easy way to do this with out checking how many are true and building a checker?
modified on Thursday, October 15, 2009 11:15 AM
|
|
|
|
|
Hi,
I have no idea what you mean by ControlButtons, did you mean CheckBoxes?
Anyway, the only way I know would be to attach this same handler to each of the relevant Controls; then either have a collection that holds the relevant controls or tag them somehow so you can easily enumerate them:
void CheckedChanged(object sender, EventArgs e) {
int count=0;
foreach(Control c in relevantControls) {
RadioButton rb=c as RadioButton;
if (rb!=null) count++;
}
if (count>MAX) {
RadioButton rb=sender as RadioButton;
if (rb!=null) rb.Checked=false;
}
}
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Yea I meant CheckBoxs or RadioButtons sorry, and yea I was looking for a way other than that.
|
|
|
|
|
You have your answers, But let me tell you there is big difrance betwen CheckBox and RadioBox
You can have a lot of checkBoxex. Each check box can be true or false
If you have more than 1 RadioBox, you can set it to true to ONLY ONE. To seperate betwen radioboxex (aka Grouping) place it in a panel
Edit: You can't check it without programming it. You need to check how many has ben set to true. There is no build in functions for your request
|
|
|
|
|
I have a Form called frmMain
In a differant class withing the same namespace I have a method (snippet):
frmMain Form1 = new frmMain();
Results(Form1.Label1);
I had expected to get the Labels name, instead I get the Labels' text. I tried Form1.Label1.Name, but that passes the name as a string versus a Label.
I am using an Event as explaind by DaveyM69 in a previous post of mine.
void Results (Label lbl_1)
{
OnUpdateLabels(new LabelsEventArgs(lbl_1));
}
Everything works and is passed over to the Forms methods, but since I am not passing a Lable name nothing happens. What I am trying to do is change the ForeColor of a lable. There are multiple labels that could be called to change. I thought about changeing everything to a string and passing the Form1.Label1.Name but I couldn't figure out, once in the Forms method how to conver the string into a Label.
modified on Thursday, October 15, 2009 11:13 AM
|
|
|
|
|
Hi,
from this and yesterday's posts, it seems to me you don't really have a clue about objects and Controls.
There is no "label's name" involved at all; if you want to operate on a Label, all you need is a reference to that Label; and I would guess Form1.Label1 returns exactly that.
I suggest you buy and study a book on C# or "Windows programming using C#"; in the time you have spent already you could have learned a lot by reading a structured book or course.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I concede to the fact that I do not know enough about what I am doing. Which is why I am asking questions. I have tried to research and find proper solutions. But when I get stuck I have to ask.
"I would guess Form1.Label1 returns exactly that" is what I thought, so when it didn't work i got to checking things. I added a Messagebox, and Converted the variable being passed to a string and found I was getting this: Systems.Windows.Form Label, Text: Text on my Lable. Now this may be because I converted it to a string, but I think "Text on my Lable" is what is being passed versus Label1.
|
|
|
|