|
|
Thank you very much for the help!;)
|
|
|
|
|
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
<br />
public void setCheckInterval(int i_checkInterval)<br />
{<br />
switch (i_checkInterval)<br />
{<br />
case 0:<br />
_i_checkInterval = -1; break;<br />
case 1:<br />
_i_checkInterval = 60000; break;<br />
case 2:<br />
_i_checkInterval = 60000 * 3; break;<br />
case 3:<br />
_i_checkInterval = 60000 * 5; break;<br />
case 4:<br />
_i_checkInterval = 60000 * 10; break;<br />
case 5:<br />
_i_checkInterval = 60000 * 15; break;<br />
case 6:<br />
_i_checkInterval = 60000 * 20; break;<br />
case 7:<br />
_i_checkInterval = 60000 * 25; break;<br />
case 8:<br />
_i_checkInterval = 60000 * 30; break;<br />
case 9:<br />
_i_checkInterval = 60000 * 60; break;<br />
}<br />
...<br />
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
|
|
|
|
|
I am not really sure how we are supose to figure out your problem from the code you have posted. Usually if you want a more accurate timer you should use the System.Timer not the standard one you get in your tool box. To get the System.timer, right click on yrou tool box, select choose item. In the .net tab look for the system.timer and select it. Now you should have the system.timer in your tool box.
Note without seeing your other code it is hard to say why the event isn't firing on time. I would guess it has to do with some other threads are keeping the CPU busy. I would guess there is something else in your code that isn't probably working they way you expect it to. If you just let the timer run by it self without anything else running and check your watch, I would guess you would see that the event would fire pretty close to 60 later.
Ben
|
|
|
|
|
Hello,
MicealG wrote: public void setCheckInterval(int i_checkInterval)
{
switch (i_checkInterval)
{
case 0:
_i_checkInterval = -1; break;
case 1:
_i_checkInterval = 60000; break;
case 2:
_i_checkInterval = 60000 * 3; break;
case 3:
_i_checkInterval = 60000 * 5; break;
case 4:
_i_checkInterval = 60000 * 10; break;
case 5:
_i_checkInterval = 60000 * 15; break;
case 6:
_i_checkInterval = 60000 * 20; break;
case 7:
_i_checkInterval = 60000 * 25; break;
case 8:
_i_checkInterval = 60000 * 30; break;
case 9:
_i_checkInterval = 60000 * 60; break;
}
...
What should this method tell us?
MicealG wrote: Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
One reason could be that you use the System.Windows.Forms.Timer (Off course you do because you said 'Tick'), which runs in the UI thread.
This can be blocked from the busy UI.
If you need it more time secure you could use System.Timers.Timer or System.Threading.Timer.
Hope it helps,
All the best,
Martin
|
|
|
|
|
I second what the other two said, but I prefer to look for the easy solutions first. Like checking the value of i_checkInteral . Seems to me that it's value is actually 2, right where you set the timer for 3 minutes, when you expect it to be 1.
|
|
|
|
|
Hello Dave,
Please tell me, what the h... is this method doing?
Is it a second timer which checks the first?
Thanks for your time
Martin
|
|
|
|
|
It's a method, called by some unknown, that just sets a misguidedly-used global variable. What happens after that, I have no idea.
|
|
|
|
|
I am guessing you have a control (probably a combobox) that is used to select one
out of a list of time periods.
If so, use the selected combobox text rather than the selected index, and do some
simple math, something like:
const int MILLISECONDS_PER_MINUTE=60*1000;
...
int delayInMsecs=MILLISECONDS_PER_MINUTE*Convert.ToInt32(myCombo.Text)
This eliminates all the code you have shown and a lot of possible bugs, and
it is immediately clear what is going on.
|
|
|
|
|
I have a conceptually simple method that gets a compiler warning (CA1502) regarding its cyclomatic complexity. The error tells me that the method has a complexity of 31 and I should reduce that to 25.
The problem is that the method isn't doing much, and the complexity is due to a switch block that maps an old DAO data type enumeration to a .NET type. For example, int for adInteger. The only thing else the code does is parse the input string into an integer. Overall, this method is part of a builder pattern based class that is responsible for taking a formatted string and converting it into a DataSet. The data comes through TCP from a legacy application that's output is based on a DAO Recordset.
At this point, I'm settling on ignoring the compiler warning, because the other options I've considered have consequences that outway the benefits. For example, implementing a look-up such as Dictionary<int, type=""> takes up memory unnecessarily. This method will either be called very rarely or very often.
Before I walk away from this, does anyone have any ideas for alternatives to this? I appreciate any advice.
Here is the code in question (I've removed some of the data types for brevity):
private static Type GetColumnDataType(string data)<br />
{<br />
int typeValue;<br />
bool parsed = int.TryParse(data, out typeValue);<br />
<br />
if (!parsed)<br />
throw new FormatException(Properties.Resources.BuilderColumnFormatMismatch);<br />
<br />
DAOColumnDataType dataType = (DAOColumnDataType)typeValue;<br />
Type resolvedType;<br />
<br />
switch (dataType)<br />
{<br />
case DAOColumnDataType.adVarChar:<br />
resolvedType = typeof(string);<br />
break;<br />
<br />
case DAOColumnDataType.adBoolean:<br />
resolvedType = typeof(bool);<br />
break;<br />
<br />
case DAOColumnDataType.adInteger:<br />
resolvedType = typeof(int);<br />
break;<br />
<br />
case DAOColumnDataType.adDouble:<br />
resolvedType = typeof(double);<br />
break;<br />
<br />
case DAOColumnDataType.adDate:<br />
case DAOColumnDataType.adDBDate:<br />
case DAOColumnDataType.adDBTime:<br />
case DAOColumnDataType.adDBTimeStamp:<br />
resolvedType = typeof(DateTime);<br />
break;<br />
<br />
<br />
default:<br />
resolvedType = typeof(string);<br />
break;<br />
}<br />
<br />
return resolvedType;<br />
}<br />
|
|
|
|
|
Hi,
you could use a HashTable to map all the DAOColumnDataType values to
their corresponding types. The table needs to be constructed only once.
If the key exists, the value is the type; if not (which corresponds to
the default case in your switch), typeof(string) is what you want.
Furthermore, if all DAOColumnDataType.ad### constants are integers within a
small range, you could even consider an array of types and use dataType
as the index (probably with a try-catch to catch excessive index values);
any intermediate non-existing ad### values should result in typeof(string).
Hope this helps
|
|
|
|
|
That was kind of what I was going for with the generic Dictionary (Dictionary<int, type="">). It just sucks up a bit of memory that I couldn't justify since the method may only be called rarely (the other scenario is that it would be used constantly).
Some of the items are continuous in their values specifically 2-7, 11, 14, 16, 20, 72, 129, 131, 133-135, and 200 are the ones handled. Doesn't seem to be any pattern there to me. Although an array would suck up the memory too. I'd probably do that in a static implementation; but, wouldn't matter anyway since System.Type objects are never garbage collected.
|
|
|
|
|
tgrt wrote: System.Type objects are never garbage collected
I dont know; seems to make sense tho.
If so, an array approach only costs 4 (or 8) B per entry, since the types exist
whatever approach you take. Hence less than 1KB. Way to go !
|
|
|
|
|
Yeah, I guess that might work the Dictionary/Hashtable approach. An array wouldn't work, because of the large spread of values. I'm creating less than 20 System.Type objects. I guess I should factor in the smaller amount of code loaded into memory.
|
|
|
|
|
I would go for the array, something like:
Type[] daTypes=new Type[256];
...
for(int i=0; i<256; i++) daTypes[i]=typeof(string);
daTypes[daConstant]=typeof(something);
...
if ((val & 255)!=val) {
type=typeof(string);
} else {
type=daTypes[val];
}
so there is even no need to try-catch;
only 1KB of data, and much faster than switch or HashTable.
|
|
|
|
|
How can I block a user from accessing a specific drive or directory??
Johnny
|
|
|
|
|
If you use:
System.IO.File.Encrypt("filename.txt")
or
<br />
DirectoryInfo d = new DirectoryInfo("C:\newfolder")<br />
d.SetAccessControl(...<br />
You can ensure that the user account that runs this code is the only one able to access the contents.
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
|
|
|
|
|
Hello,
Have no idea why you got downvoted, got my "5" to bring it back in shape.
I'm always a little pissed if somebody is doing so without any commend! (helps nobody)
All the best,
Martin
|
|
|
|
|
I didn't do it, but it would appear that his solutions didn't address the question asked at all.
They specified encrypting files or setting permissions on folders, but the question asked how to block access to entire drives and folders.
Encryption won't really help at all. Setting permissions will, but is difficult to manage, depending on the requirements of the application.
|
|
|
|
|
Dave Kreskowiak wrote: that his solutions didn't address the question asked at all.
I do recognized that half of his answere would not help sofing the question, but permission is a way to do it (at least he could try it).
Dave Kreskowiak wrote: I didn't do it
I would always expect a statement from you which helps also the one who answered the question.
That's one of the reasons I'm answering questions here (never stop learning!)
All the best,
Martin
|
|
|
|
|
In your code - you don't do anything. This is best left up to Group Policies. Pickup the Resource Kits for Windows XP or Windows Server 2003 and it's explained ad nauseum.
|
|
|
|
|
Hi all,
I created an MDI application, still with .NET Framework 1.1, and a child form has a user control in which is defined a AxWebBrowser control.
I wanted to disable Ctrl+N and Ctrl+P keystrokes, so I implemented the MsHtmlHstInterop.IDocHostUIHandler interface on the user control and changed the TranslateAccelerator method to do so, but it doesn't seem to be called.
Everything's working with no MDI application.
Could you help me, please?
Thanks.
Daniele Camanni.
|
|
|
|
|
Hi,
I am new to sharepoint technology. can anyone give me a sample C# code to access the sharepoint/wss3.0 site from remote machine without using Web Service.
Thanks
Ramamurthi
ramamurthic@gmail.com
|
|
|
|
|
Hi,
I have some textboxes on a tabpage using binding to show data, but it seems that the Text property of my textboxes are empty when they are on a not visible tabpage. (when the textboxes are visible the value of the text property is OK)
After switching to the tabpage, the field data is shown in the textbox and the text property is also OK.
------------------------------
The problem i have now is, that the component to verify the "Text" entered by the users gives a fault because some fields are empty..
and they are not because the dataset has only been set to modify...
(when switching to all tabs without modifying data i can post the row again.)
Has anyone a solution, a suggestion for this or do i need to workaround the problem ...
Thx
Kurt
|
|
|
|
|
hi ,
can any body tell why is the error fail to load view state in grid view in c#.net
|
|
|
|