|
Hope this helps[^]
better one[^]
Until you realize this message has nothing to say, its too late to stop reading
modified on Tuesday, April 8, 2008 1:09 AM
|
|
|
|
|
I think I didnt write my post properly..
I dont want to make a windows service.. Since that would be too high on performance.. I want to make a kind of windows scheduler which executes some other program at specified intervals of time (say once in every 3 hours or once weekly)..
I know this may be achieved by adding a task to windows scheduler..
So how can I add a task to the windows scheduler programaticaly using C# so that it may run at specified intervals of time??
Any help would be appreciated..
Som
|
|
|
|
|
The service applicaion will help you create the scheduled applicaion.
First create service applicaiton. This appliciaon relate with your applciaon.Then you can solve the probelm.
Continue...
|
|
|
|
|
C#, How to check an object to see if it is a numeric value?
something like this?
if (IsNumeric(intnumber))
{
return intnumber
}
else
{
return 0
}
|
|
|
|
|
int iValue<br />
bool isInteger = int.tryparse(yourObject, out iValue);
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
Can we put it an if statement?
If (isNumeric(myObject)
{
return myObject
}
|
|
|
|
|
dougins wrote: If (isNumeric(myObject)
Where did isNumeric came from?
If you are talking about Microsoft.VisualBasic.Information.IsNumeric(object) then cant use it.
Until you realize this message has nothing to say, its too late to stop reading
|
|
|
|
|
The only place that IsNumeric exists, is for a char. The TryParse methods take a string, so if you have an object, you need this:
string testVal = myObject.ToString();
double d;
if (double.TryParse(testVal, out d))
{
// I used double because 23234.545 is a number and int.TryParse won't accept it
// I assume double.TryParse can parse a whole number.
}
The other way to do it is
bool isNumeric = true;
foreach(char c in myObject.ToString())
{
if (!char.IsNumber(c))
{
isNumeric = false;
break;
}
}
But this is more code, and again, it depends on if you care about decimals, writing a method to check decimals is even more messy ( you must accept one and only one decimal, and you need to respect culture, some cultures use , as a decimal point.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
object obj = 10;
string str =Convert.ToString(obj);
Console.WriteLine(char.IsNumber(str, 0));
Console.Read();
Hi friend u can use this functionality and solve the issue.
Continue...
|
|
|
|
|
Wow - after two correct answers, you offer an incorrect one. Brilliant. This will work *sometimes*, but is far from foolproof.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Assume obj is some object .
To check if that is a number, you could use:
bool isNumber = Regex.IsMatch(obj.ToString(), @"^(\-|\+)?\d+[.]?\d*$");
SkyWalker
|
|
|
|
|
|
It depends on what you are actually doing.
Why would someone put that check inside a constant looping?
SkyWalker
|
|
|
|
|
Assuming you had something like:
int number = 5;
...
object obj = number;
or
object obj = 5;
Then you could just use:
if(obj.GetType() == typeof(Int32) {
}
or even simpler still:
if(obj is Int32)
You may also want to check for Int16 and Int64 (or you can check for short, int and long, oh yeah and there's also float and double to check for as well. And the unsigned versions of the types)
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
Hi, i'm writing a program about copy files from one place to other place. When the copy process start, it will shows up a form and tells user what file are being copied and there is a button to allow the user to stop the process. My problem is i cannot make the "stop" button works.The program code is like this:
======Copy Form======
private void StopButton_Click(object sender, EventArgs e)
{
frmTest.Stopcopying = true;
return;
}
=======Main form(frmtest) ========================
....
public static bool Stopcopying = false;
...
public static void copyDirectory(string Src, string Dst) {
String[] Files;
fmCopying.StartPosition.Equals("Center");
if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
Dst += Path.DirectorySeparatorChar;
if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
// int[] result = Array.FindAll(Files, delegate(int i){}
frmCopying fmCopying1 = new frmCopying();
fmCopying1.Show();
foreach (string Element in Files)
{
fmCopying1.Refresh();
// Sub directories
if (Directory.Exists(Element)){
if (frmTest.Stopcopying == true)
{
fmCopying1.Close();
return;
}
copyDirectory(Element, Dst + Path.GetFileName(Element));
fmCopying1.Refresh();
fmCopying1.lblCopying.Text =Element;
fmCopying1.lblCopying2.Text = Dst + Path.GetFileName(Element);
fmCopying1.Refresh();
} // Files in directory
else
{
if (frmTest.Stopcopying == true)
{
fmCopying1.Close();
return;
}
File.Copy(Element, Dst + Path.GetFileName(Element), true);
fmCopying1.Refresh();
fmCopying1.lblCopying.Text =Element;
fmCopying1.lblCopying2.Text = Dst + Path.GetFileName(Element);
fmCopying1.Refresh();
}
}
fmCopying1.Close();
}
....
try
{
if (frmTest.Stopcopying == true) throw null;
copyDirectory(@path, @mapto);
} catch (Exception err)
{
{
string errrr = "Error: " + err.Message;
MessageBox.Show(this, errrr, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
If i click on the stop button the window will freeze and the copy process don't stop..
My though in the code maynot be the best way of doing it, any ideas are welcome, many thanks for your help
|
|
|
|
|
Hi,
if you call the copyDirectory method on the GUI thread (say inside a button click handler,
or a form load handler), then the GUI will be blocked as long as the copy takes, hence
the stop button will not work during that time, making it useless.
the right solution is to perform the copyDirectory on a separate thread, which gets
launched by the start button or the form load handlers, and which does not run on the
GUI thread, so you can move, resize, etc while the copy is going on; and you now can
use the stop button.
Warning: if you need to update the GUI (say show the filename currently being copied)
you would need Control.InvokeRequired and Control.Invoke to do so.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
many thanks, Luc. I am now rewriting the Copy form and add Thread method to it, so when it starts it will open a new thread and start the copy method. But i don't quite get how to get Control.InvokeRequired and Control.Invoke works, can you please give a bit example or a bit explainlation of them? many thanks again!
daniel
|
|
|
|
|
Use a delegate whenever you want to update controls created within other threads (i.e. to avoid cross-thread operations):
delegate void SomeActionCallback( Control yourControl, ... other params here ... );
void SomeAction( Control yourControl, ... other params here ... )
{
if (this.IsDisposed) return;
if (yourControl.IsDisposed) return;
if (yourControl.InvokeRequired)
{
SomeActionCallback deleg = new SomeActionCallback(SomeAction);
this.Invoke(deleg, new object[] { yourControl, ... pass other params here ... });
}
else
{
}
}
Call SomeAction() whenever you want to update the controls of your form from a thread event handler.
SkyWalker
|
|
|
|
|
|
Yeah, but the "cros thread operation" is still there
SkyWalker
|
|
|
|
|
hi i have come accross a problem that after the process completed i cannot start the copy process again once it have completed. It complains "The object have been disposed", My question is how can i check if the bw have been stoped and i can start another bw(oR create a new bw)?
I used the GUI to make the bw, it generates this
private BackgroundWorker bw;<br />
...<br />
<br />
this.bw = new System.ComponentModel.BackgroundWorker();<br />
...<br />
this.bw.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_DoWork);<br />
this.bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted);<br />
<br />
.....<br />
<br />
<br />
<br />
public static void copyDirectory(string Src, string Dst)
{<br />
String[] Files;<br />
<br />
<br />
fmCopying.StartPosition.Equals("Center");<br />
<br />
<br />
if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)<br />
Dst += Path.DirectorySeparatorChar;<br />
if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);<br />
Files = Directory.GetFileSystemEntries(Src);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
foreach (string Element in Files)<br />
{<br />
<br />
fmCopying.Refresh();<br />
<br />
if (Directory.Exists(Element)){<br />
<br />
<br />
<br />
System.Threading.Thread.Sleep(1000);<br />
copyDirectory(Element, Dst + Path.GetFileName(Element));<br />
<br />
fmCopying.Refresh();<br />
fmCopying.lblCopying.Text =Element;<br />
fmCopying.lblCopying2.Text = Dst + Path.GetFileName(Element);<br />
fmCopying.Refresh();<br />
<br />
<br />
<br />
<br />
}
else<br />
{<br />
<br />
<br />
<br />
<br />
<br />
System.Threading.Thread.Sleep(1000); <br />
File.Copy(Element, Dst + Path.GetFileName(Element), true);<br />
fmCopying.Refresh();<br />
fmCopying.lblCopying.Text =Element;<br />
fmCopying.lblCopying2.Text = Dst + Path.GetFileName(Element);<br />
fmCopying.Refresh();<br />
<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
fmCopying.Close();<br />
<br />
<br />
}<br />
<br />
.....<br />
<br />
private void bw_DoWork(object sender, DoWorkEventArgs e)<br />
try<br />
{<br />
<br />
<br />
<br />
<br />
<br />
<br />
copyDirectory(@path, @mapto);<br />
<br />
<br />
<br />
<br />
<br />
<br />
}<br />
catch (Exception err)<br />
{<br />
{<br />
<br />
string errrr = "Error: " + err.Message;<br />
MessageBox.Show(this, errrr, "", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
bw.WorkerSupportsCancellation = true;<br />
<br />
<br />
<br />
fmCopying.Show();<br />
<br />
<br />
bw.RunWorkerAsync();
* / */
|
|
|
|
|
You can find a lot of coding examples on the net.
This[^] is one of them.
SkyWalker
|
|
|
|
|
View a printable version of this message! I'm working on building a web-based solution (c# + .net) to allow users to
manage AD groups that they have appropriate rights to manage. On all groups
in Active Directory, there is an advanced permission called "Write Members".
If the user (who logged in via a forms based login page) is granted that
permission on the group (either directly or by being a member of a group that
has been granted the necessary permission), they should be able to update the
group membership. The web app has its own user account with enough
permissions to update the group, but I don't know the best way of having it
determine if it should use it's powers to update the membership for the user.
My question: What is the best way to handle this, and is there a way for me
to just pass the user DN (or SID, SAMAccountName, etc), and have AD determine
if it that user is allowed to access that object.
I've found code that should be able to get the user's security token, and
parse the SIDs it contains. I'm assuming I could then take that list of
SIDs, and compare it to the list of users/groups that have Write Members set
to allow on the group in question. This seems ugly/wrong. There are too
many cases where this falls short (i.e. the user is a member of a group that
doesn't have the Write Members permission, but it does have the Write All
Properties permission. It also doesn't effectively check for deny entries.)
It feels like there should be a way for me to simply [programatically] ask AD
if user X has access to update the "member" attribute on a given group.
I am a Systems Engineer and not (yet) a programmer, so a little more verbose
answer is very much appreciated.
Thanks!
|
|
|
|
|
perhaps using LDAP ? My program can allow AD users to change their password by their own.
I'm not sure does this works in your case. You can try.
|
|
|
|