|
Thanks for your reply Bob.
I like to write a generic service that handles day light savings. It doesn't matter when it will change.
Service needs to check system time every minute to find out if it is the time to run the service or not. That way even day light savings time changes, service runs at correct time without out of sync.
|
|
|
|
|
Is it possible to test and debug source code which deals with UI and non-UI thread exceptions using Application.ThreadException and AppDomain.CurrentDomain.UnhandledException events?
Regards,
matixsc
|
|
|
|
|
|
I'm not aware of a "space bar button" and I certainly don't have and ASAP.
Asking for an answer ASAP is rude. You need to clarify what you are clicking.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
sachinss1986 wrote: ASAP
Naughty - advice for your future at codeProject - don't use ASAP or Urgent or anything similar. Just ask your question politely with plenty of detail (but not too much) and your far more likely to get a quick answer.
I'm not sure why your rows are deleting. I don't use the dgv myself so not much experience with it but I'm sure it's not the default behaviour so maybe you have KeyDown/Up/Press handler somewhere that's doing this?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
I'm wondering where a setting's value comes from, if it is not configured in MyApplication.exe.config.
Didn't find an answer at msdn yet, so could anyone explain please?
|
|
|
|
|
The default value is hard coded as an attribute on the property. Look in the Settings.Designer.cs file for the "DefaultSettingValueAttribute" attribute on each property.
Note that "user" scope settings can also be stored in a config file in the documents and settings/username/localsettings/application data folder.
Simon
|
|
|
|
|
Simon Stevens wrote: The default value is hard coded as an attribute on the property
Thanks, that's what I've been looking for.
|
|
|
|
|
I beleive the info is stored in the appconfig file. So when you right click your application in the explorer window and select properties, the settings tab allows you to store information in the app config table.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
<big><u><b>How can i restore my application from system tray if it is already running</b></u></big>. In my application i have coded to run my application at system startup in minimized state. So i want to maximize my application window when the user clicks the desktop shortcut icon. <u><b>I used Mutex method, ShowWindow P/Invoke method</b></u>. But I cant get the correct one. These two methods restore the application only if the application is minimized in taskbar. Any one can help me quickly.
|
|
|
|
|
Using the mutex is the correct way.
You need a delegate in your main form which calls a Restore method (Visible = true; WindowState = ... etc). Whilst checking your mutex, at the point where you decide you don't need the new instance, invoke the delegate.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You can use mutex to detect whether you are first instance or not. For communicating with an already running process you can use either IPC or .NET Remoting. There are classes in .Net Framework for all of these.
|
|
|
|
|
Hello!
I use a program which runs several threads to simulate diffrent devices. Each thread simulate one device.
I have no problemmen staring the threads, but I don't know how to pause them. With pausing, I mean the thread should be stopped but not terminated.
Later in the program I wish to restart/continue the threads.
I have tried to use the suspend() and resume() methods, but I have read that those methods are not good to use for this. I also get irritating warnings when I compile the code, with susped() and resume() methods, which suggest I should use some other solution instead of suspend() and resume() methods.
This is my windows application code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
new Bar1("bar1");
new Bar2("bar2");
}
private void btnExec_Click(object sender, EventArgs e)
{
if (!DeviceBase.Run)
{
DeviceBase.execAll();
}
else
{
}
DeviceBase.Run = !DeviceBase.Run;
}
}
abstract class DeviceBase
{
public static Dictionary<string, DeviceBase> devices = new Dictionary<string, DeviceBase>();
private string name;
private Thread execThread;
protected static bool run = false;
public DeviceBase(string name)
{
this.name = name;
devices[name] = this;
devices[name].execThread = new Thread(exec);
}
public string Name
{
get
{
return name;
}
}
public static bool Run
{
get
{
return run;
}
set
{
run = value;
}
}
public static void execAll()
{
foreach (string device in devices.Keys)
{
if (devices[device].execThread.ThreadState == ThreadState.Unstarted)
{
devices[device].execThread.Start();
}
else
{
}
}
}
public static void pauseAll()
{
}
protected virtual void exec()
{
}
}
class Bar1 : DeviceBase
{
public Bar1(string name) : base(name)
{
}
protected override void exec()
{
while (run)
Console.WriteLine(Name + " is running");
}
}
class Bar2 : DeviceBase
{
public Bar2(string name) : base(name)
{
}
protected override void exec()
{
while (run)
Console.WriteLine(Name + " is running");
}
}
I have created two diffrent devices (instances) with the classes 'Bar1' and 'Bar2' in the 'Form1' constructor. Each device class derive from the abstract base class 'DeviceBase'' and each 'Bar-instance' overrides the base class method exec(). The 'exec()'-method is the simullating-method which each thread is using/running.
The thread is connected to the derivied 'exec()'-method when the base instance is created.
I use a button: 'btnExec', in the Windows Application form: ´Form1' to start/continue and pause the threads. The static method in the base class: 'execAll()' starts all threads, if the threads are in 'unstated'-state.
To pause the threads, I would like to use the static method: 'pauseAll()' and to continue the threads again I would like to use the 'execAll()'-method again.
How do I solve this?
|
|
|
|
|
you could change the run boolean to an enum that looks like this:
enum EXECUTION_STATE
{
RUNNING,
SUSPENDED,
STOPPED
}
so that your while loop could be changed to this (after renaming run to something more appropriate):
while (state != EXECUTION_STATE.STOPPED)
{
if (state == EXECUTION_STATE.RUNNING)
{
Console.WriteLine(Name + " is running");
}
else
{
Thread.Sleep(500);
}
}
|
|
|
|
|
Thanks, maybe sleep() method is the easiest solution.
But... I don't know how long the thread should be sleepiing/paused.
Maybe this works, if I add in the 'else' statement?
else
{
Thread.Sleep(Timeout.Infinite);
}
|
|
|
|
|
Mc_Topaz wrote: else
{
Thread.Sleep(Timeout.Infinite);
}
You can never resume from that sleep. I'd suggest using some sort of signaling mechanism, like ManualResetEvent[^]. Your code will look roughly like this
AutoResetEvent evt = new AutoResetEvent(false);
public void Pause()
{
executionState = PAUSED;
}
public void ThreadFunc()
{
while (true)
{
if (executionState == PAUSED)
evt.WaitOne();
}
}
public void Resume()
{
executionState = RUNNING;
evt.Set();
}
|
|
|
|
|
it looks like S. Senthil Kumar has a good idea. I just used a Sleep(500) because it's a quick and easy way to prevent the thread from hogging the processor when it doesn't need it. You can make it do whatever you need it to when it's paused.
|
|
|
|
|
Jimmanuel wrote: I just used a Sleep(500)
And slow down your thread? Why? Just use Sleep(0) if you want to yield to other threads
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
true, but the side goal was to slow down the thread. Sleep(0) will also return execution to the thread as soon as the OS can which, again, will peg the CPU usage for the thread at an unnecessarily high percentage. That's bad for my laptop's battery life
|
|
|
|
|
Hi,
I am developing an application which uses a web-service that is only available in our client's intranet. My problem is that the development environment is not inside the intranet... So, to add the web reference, I can download the .wsdl file from the intranet (using a different computer), copy the file into our dev environment... then what?
What I want is to get visual studio to auto generate the asmx and the Reference.cs files... Is there a tool which I can copy into the "intranet computer" so it can gather the files necessary?
Thanks.
Rafferty
|
|
|
|
|
You can use the WSDl.exe tool in the SDk to create the web service classes by hand. Those are basically equivalent to your Reference.cs, generated by the VS wizard.
|
|
|
|
|
Hi,
how can i set, get (whatever) data in parameters field on a crystal report. I create a blank report, i also create datasets by code so i can´t drag database fields to the report, just empty fields there!
I want to this by code, so don´t want to change.
Other think is that i can find a field to load pictures (IBlobFieldObject), you have string int date etc, but not any byte [].
(I only get that field if use the design method for dataset and report)
Links, code or advice are welcome
Thanks
nelsonpaixao@yahoo.com.br
trying to help & get help
modified on Thursday, October 9, 2008 8:11 PM
|
|
|
|
|
Hi
Really after some advice if anyone is willing regarding how I can create a class containing arrays or structures. Simple to answer probably but im struggling becuase I come from a procedual C background and havent ever done OO - I just thought it would be interesting to learn - (Trip to the book store on Saturday Morning planned!!!)
Basically what I would like to do is have a class that contains an array. And I want to create an array of these classes to. So I guess something like this -
public class DataStore
{
private static int numberOfStores;
ArrayList myList = new ArrayList()
public DataStore()
{
numberOfStores++;
}
public void ValuesinArray(float ValueToAdd)
{
myList.Add (ValueToAdd);
}
}
public class Application
{
static DataStore[] x = my DataStore[30];
}
Now I get stuck after there! Is anything like this anywhere near correct? How would I add and get stuff from my array (Ideal I want to have several arrays there of for different things but all of the same length)
Are ArrayLists correct? Is there a way to make the array of classes dynamic instead of setting it to a constant of say 30?
Can anyone recommend a resource that details building more complicated objects?
TIA!
David
|
|
|
|
|
davidbrammer wrote:Are ArrayLists correct
I would suppose that would depend on what you are using the array for and how you want to use it. There are many collection classes in .NET.
davidbrammer wrote:array of classes dynamic
You would use a dynamic collection not an array per se. You could use a List for your collection of DataStores. List<datastore> ds = new List<datastore>();
/Edited seems the quoting is not working correctly.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
I have a little macro that I use to auto generate a basic class and collection of that class when I need that sort of functionality.
Sending 'DataStore' to that creates two files DataStore.cs and DataStoreCollection.cs with these contents (namespace and usings ommited!).
public class DataStore
{
public DataStore() { }
}
public class DataStoreCollection : List<DataStore>
{
public event EventHandler CollectionChanged;
private static DataStoreCollection instance;
public static DataStoreCollection GetInstance()
{
if (instance == null)
{
instance = new DataStoreCollection();
instance.Initialize();
}
return instance;
}
private void Initialize()
{
}
public new void Add(DataStore item)
{
base.Add(item);
OnCollectionChanged();
}
public new void Remove(DataStore item)
{
base.Remove(item);
OnCollectionChanged();
}
protected virtual void OnCollectionChanged()
{
if (CollectionChanged != null)
{
try
{
CollectionChanged(this, EventArgs.Empty);
}
catch { }
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|