|
Thanks for the replies!! Using the ManualResetEvent and a timer was a massive improvement - 201 or 202ms normally although I soon realised, sleeping for 200ms instead of for 1ms 200 times originally would have resulted in far less context switching and greater accuracy. I will take a look at the article for more info but think that for my application, this could be good enough.
I'm still not entirely sure why Vista exaggerated this problem so much in comparison to XP but my current solution works equally well for both so I am happy.
Thanks all for your help!!
|
|
|
|
|
Could be any number of reasons. Timeslices appear machine dependent so if you were running on different physical boxes (or physical vs VM) that could be to blame. Other suspects are more background processes, or one running at a higher level when you were doing the testing, or general scheduler changes. ie if vista felt your hammering with 1s sleeps was being bad and was giving higher priority to other apps as a result.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Another impactor would be if the different machine had different CPU / core counts, or were doing "Hyperthreading".
Absolutely, time slices are non-deterministic.
|
|
|
|
|
threading is nondeterminisitic and cannot be controlled on your end. Your Thread.Sleep(1) call is telling the OS "I'm taking a break and ignore me for one 1ms". After the ms passes control does not return to your thread, instead your thread is added back to the pool of threads that the OS scheduler looks at for picking the next thread to run. Context switching is however an expensive process and normally a thread will be run a few dozen ms before the scheduler stops ti and passes control over to another thread.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Hi,
I explained these kinds of phenomena in my timer article. Have a read!
|
|
|
|
|
Hi,
The code loops through a list of machineNames and for each machinName (There are 18 of them), it loops through a number of settings (There are 39 of them).
At present I have a generic collection to populate all the settings which is called settings.
As I am looping through the settings of each machineNames, I modify the (Fields) appropriate to that MachineName in the settings loop...
In additin I also have a class which holds the fields. This is called clsSetting
This is what I have at present:
private List<DataAccess.clsSetting> settings = new List<DataAccess.clsSetting>(); //collection to hold settings...
//generic collection to hold the result
private List<List<DataAccess.clsSetting>> results = new List<List<DataAccess.clsSetting>>();
//loop through the machineName...
foreach (DataRow dr in _dtMachineNames.Rows)
{
foreach (DataAccess.clsSetting s in settings)
{
//modify these fields for the machineName in the loop...
s.Server = strServername;
s.Result = strResult
//the other fields are not modified...
}
//??????????????????????????
//This is where my question is:
//here I would like to have another collection which holds all the settings for each machineName
//something like:
results.Add(settings)
}
Question:
When I try the above code, i.e. results.Add(settings)
The results collection get added but NOT correctly.
It seems the data in it for each index gets over written because in the above code I modify some of the fields.
Can you please let me know what is wrong here?
Thanks
|
|
|
|
|
Hi,
Each time you loop through settings collection, you actually modify the original element in the settings collection. And again when you add settings to results, you actually add the same references again and again. Later changes on the original element (s) affect all the elements int the result list pointing to the same element.
So, you should create a copy from s before modifying and storing it to another collection if you want the elements to have independent values.
I think you also find several helpful articles here in CP. For example http://www.codeproject.com/KB/dotnet/Primitive_Ref_ValueTypes.aspx[^]
Mika
|
|
|
|
|
Hi...
I need to enable my Apply button only when the user edits something on the form (I have datagrids, text-, check-, comboboxes). All of them are bounded to a Databinding.
What's the best way to get this behaviour?
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
With a keypress event
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
I'd bind the "Enabled" property to my business object. So when value gets changed there, it gets enabled/disabled automatically. Check this[^] article.
|
|
|
|
|
In a textbox_input_textchanged event put button_apply.enable = true
|
|
|
|
|
how to Change crystal reports Runtime Location of OLE Object
|
|
|
|
|
I have created the excel object which creates a process Excel.exe, see the code below
Microsoft.Office.Interop.Excel.Application Excelobj = new
Microsoft.Office.Interop.Excel.Application();
Excelobj.quit();// calling this doesn't ends the Excel.exe so how do i kill
this excel.exe
|
|
|
|
|
Have you used Marshal.FinalReleaseComObject() on every COM object? Have you set them to null ? Finally, have you used GC.Collect() once when you've finished doing those things?
|
|
|
|
|
// I have used this function still problem persists
protected void killExcel(Microsoft.Office.Interop.Excel.Application exc)
{
try
{
List<microsoft.office.interop.excel.workbook> wbs = new List<microsoft.office.interop.excel.workbook>();
List<microsoft.office.interop.excel.worksheet> wss = new List<microsoft.office.interop.excel.worksheet>();
foreach (Microsoft.Office.Interop.Excel.Workbook wb in exc.Workbooks)
{
foreach (Microsoft.Office.Interop.Excel.Worksheet ws in wb.Worksheets)
wss.Add(ws); // collect worksheets
wbs.Add(wb); // collect workbooks
}
for (int i = 0; i < wss.Count; i++)
{
wss[i].Delete();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wss[i]); // release it
wss[i] = null; // null it
}
for (int i = 0; i < wbs.Count; i++)
{
wbs[i].Close(null, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs[i]); // release it
wbs[i] = null; // null it
}
exc.Workbooks.Close(); // so you can close this
exc.Quit(); // so you can quit this
System.Runtime.InteropServices.Marshal.ReleaseComObject(exc); // release it
exc = null;
GC.Collect(); // this sets up the finalizers
GC.WaitForPendingFinalizers();
GC.Collect(); //apparently this kills it
GC.WaitForPendingFinalizers();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
// deal with it fool!
}
}
|
|
|
|
|
I'm using :
ApplicationClass appClass = new ApplicationClass(); -> open
appClass.Workbooks.Close();
appClass.Quit(); -> it close excel.exe
|
|
|
|
|
I found this in the documentation on one of the COM Release functions:
// Note that COM objects that raise events within a .NET client require two Garbage Collector (GC)
// collections before they are released. This is caused by the reference cycle that occurs between
// COM objects and managed clients. If you need to explicitly release a COM object you should call
// the Collect method twice.
So I do a double GC on the main app object if I've setup any event handlers for it.
|
|
|
|
|
Something else you can investigate. Are you checking the return value from System.Runtime.InteropServices.Marshal.ReleaseComObject()?
It contains the reference count on the object. Check the return value to see if it's not zero. It would be interesting to know if on those times when Excel refuses to exit, the ref count is not zero.
The documentation actually suggests calling ReleaseComObject in a loop UNTIL the return value is zero.
|
|
|
|
|
Hi, when I open a dbf table with dBALite I can see under Database Info whether a table is ANSI or not...
Is there a way to get the same information when I open that table in a C# program?
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
Probably, but that would be something database specific...
Normally you don't need to care about the encoding. The database driver should give you string data as strings, not as encoded byte arrays.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Normally not... but the problem is that all language specific char may not be read correctly. For exemple instead of ü i get | ... to solve that problem I have to decode the table (this is already done)
The problem is that some times I get tables that are already encoded correctly... in that case I don't need to decode the table...
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
Hi
I am with a cheque printing software, how can I print a forms textbox data with out the forms background
Thanks & Regards
modified on Thursday, July 24, 2008 3:39 AM
|
|
|
|
|
Have a look at the PrintDocument[^] class.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I'm trying to connect remotely from phone to pc. Currently I tested it in cradle mode. When I tried running my program (which is in the phone) it occured an error: Cannot find DbNetlib.dll. However, when I tried a pc to pc wireless connection (using an emulator) it works. It connects to the server just fine. Does anyone know how I can make my PDA phone connect to the server? I'm just copying the .exe file of my project file by the way.
modified on Thursday, July 24, 2008 3:45 AM
|
|
|
|
|
harcaype wrote: Cannot find DbNetlib.dll
And do you expect that it SHOULD be able to find this dll ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|