|
Within your app, yes - but it will only work if your app is running at the time.
If it isn't, you can't use a class to do that, because all class instances are destroyed at the end of the app.
You can however run an app at a specific time each day: Task Scheduler (Windows)[^] will let you do that pretty easily.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thanx, for example its a file checker, with start and stop function, at a specific time i would like it to stop and restart agin, while the app is still on. is there code i can view to help me with this
|
|
|
|
|
Just create a background thread - see the BackgroundWorker class[^] for a simple method and an example.
Then in the thread, use DateTime.Now to get the current date and time, and if you are outside the "running" time, call Thread.Sleep(60000) to wait for one minute before trying again.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
I'd tend to go with an Rx solution where I calculated the time difference between now and the end time, then use that as the parameter in an Onservable.Timer[^]. Then again, I have obviously have masochistic tendencies
This space for rent
|
|
|
|
|
Why don't you do this via a Windows service? A Windows service will run even if a user isn't logged on the machine. You can use a config file to control processing, or if it's a file checker, it will watch the specified file for changes (or folder for new files), and react accordingly.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
 well am thinking of putting it on a server.
{
public partial class frmNotifier : Form
{
private StringBuilder m_Sb;
private bool m_bDirty;
private System.IO.FileSystemWatcher m_Watcher;
private bool m_bIsWatching;
public frmNotifier()
{
InitializeComponent();
m_Sb = new StringBuilder();
m_bDirty = false;
m_bIsWatching = false;
}
private void btnWatchFile_Click(object sender, EventArgs e)
{
if (m_bIsWatching)
{
m_bIsWatching = false;
m_Watcher.EnableRaisingEvents = false;
m_Watcher.Dispose();
btnWatchFile.BackColor = Color.LightSkyBlue;
btnWatchFile.Text = "Start Watching";
}
else
{
m_bIsWatching = true;
btnWatchFile.BackColor = Color.Red;
btnWatchFile.Text = "Stop Watching";
m_Watcher = new System.IO.FileSystemWatcher();
if (rdbDir.Checked)
{
m_Watcher.Filter = "*.*";
m_Watcher.Path = txtFile.Text + "\\";
}
else
{
m_Watcher.Filter = txtFile.Text.Substring(txtFile.Text.LastIndexOf('\\') + 1);
m_Watcher.Path = txtFile.Text.Substring(0, txtFile.Text.Length - m_Watcher.Filter.Length);
}
if (chkSubFolder.Checked)
{
m_Watcher.IncludeSubdirectories = true;
}
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
}
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.FullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
}
}
private void OnRenamed(object sender, RenamedEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.OldFullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append("to ");
m_Sb.Append(e.Name);
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
if (rdbFile.Checked)
{
m_Watcher.Filter = e.Name;
m_Watcher.Path = e.FullPath.Substring(0, e.FullPath.Length - m_Watcher.Filter.Length);
}
}
}
private void tmrEditNotify_Tick(object sender, EventArgs e)
{
if (m_bDirty)
{
lstNotification.BeginUpdate();
lstNotification.Items.Add(m_Sb.ToString());
lstNotification.EndUpdate();
m_bDirty = false;
}
}
private void btnBrowseFile_Click(object sender, EventArgs e)
{
if (rdbDir.Checked)
{
DialogResult resDialog = dlgOpenDir.ShowDialog();
if (resDialog.ToString() == "OK")
{
txtFile.Text = dlgOpenDir.SelectedPath;
}
}
else
{
DialogResult resDialog = dlgOpenFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
txtFile.Text = dlgOpenFile.FileName;
}
}
}
private void btnLog_Click(object sender, EventArgs e)
{
DialogResult resDialog = dlgSaveFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
FileInfo fi = new FileInfo(dlgSaveFile.FileName);
StreamWriter sw = fi.CreateText();
foreach (string sItem in lstNotification.Items)
{
sw.WriteLine(sItem);
}
sw.Close();
}
}
private void rdbFile_CheckedChanged(object sender, EventArgs e)
{
if (rdbFile.Checked == true)
{
chkSubFolder.Enabled = false;
chkSubFolder.Checked = false;
}
}
private void rdbDir_CheckedChanged(object sender, EventArgs e)
{
if (rdbDir.Checked == true)
{
chkSubFolder.Enabled = true;
}
}
private void frmNotifier_Load(object sender, EventArgs e)
{
}
}
}
thats a full code of filemonitor i found online.
am trying to edit it in such a way that when i click the exe file it already starts checking the files, without having to click the start button and stop button.
|
|
|
|
|
Like I said, write it as a windows service, and it can just sit there watching the file/folder without any user interaction at all.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
thanks, so am new to programing, how can i write it as a windows service? sorry for asking too much,
|
|
|
|
|
0) I suspect that you don't have the requisite skillset to handle it. Windows services require a more intimate knowledge of how Windows works.
1) The act of writing a Windows service cannot possibly be covered on a programming forum. However, CodeProject has many dozens of articles that can show you the basics.
2) As a new developer, if you learn nothing else, learn this - google is your friend. If you don't learn how to use google, your development career will be less than stellar. Here's a Microsoft site that explains how to write a Windows service. I found it with google.
Walkthrough: Creating a Windows Service Application in the Component Designer | Microsoft Docs[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 2-Feb-18 6:59am.
|
|
|
|
|
Sort of. All you can guarantee is that, at some point, you should be able to make the application stop. The reason that I'm being cagey about this is because you can't exactly guarantee the point at which an operation is going to be run on a computer because there might be other tasks running that push your timing slightly out.
This space for rent
|
|
|
|
|
thanx, for example its a file checker, with start and stop function, at a specific time i would like it to stop and restart agin, while the app is still on. is there code i can view to help me with this
|
|
|
|
|
how to create the image button using asp.net program and how to browsing the image?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
And we have no idea what you have tried, where you are stuck, or what help you need. Heck, we don;t even know what you mean by "how to browsing the image?"
So tell us these things! Help us to help you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
// the code below works for reading the header, but what is the extension method for reading the footer ?
Word.Range range = selection.HeaderFooter.Range;
string HeaderText = range.Text;
|
|
|
|
|
|
Here's a weird one.
I have a class library assembly with the following (pseudo)code:
namespace MyStaticNameSpace
{
public static partial class MyStaticClass
{
public static void MyMethod1()
{
}
}
}
In my (MVC web) application (that references the assembly described above), I have this:
namespace MyStaticNameSpace
{
public static partial class MyStaticClass
{
public static void MyOtherMethod()
{
MyMethod1();
}
}
}
My problem is that the code in the app can't see MyMethod1 in the library assembly. What am I missing?
I event tried using "MyStaticClass.MyMethod1(); "...
When I try to reference methods in MyStaticNameSpace.MyStaticClass from anywhere else in the app, it sees all methods in both the assembly and the local namespace extension.
If I rename the app's class to something other than MyStaticClass, I can then do this - MyStaticClass.MyMethod1() , but that defeats the purpose of making the class partial.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 30-Jan-18 9:43am.
|
|
|
|
|
John Simmons / outlaw programmer wrote: What am I missing? The fact that they're two completely different classes.
You can only use partial to split a class into different files within the same project.
Partial Classes and Methods (C# Programming Guide) | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I'm missing most of my cerebral material this morning. :/
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm new to the unit-testing world and want to know how I can improve and write better tests 
|
|
|
|
|
Buy a book on the topic, find tutorials, and practice.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Any recommended book? 
|
|
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|