|
take a look @ GetLastInputInfo on MSDN
set the bounds according to SystemInformation.VirtualScreen properties and you got the basic idea how to accomplish.
And we really encourage "?" signs here so we know what to answer to
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
I heard that starting in Windows 95, Microsoft actually provided screen savers with the operating system. Maybe you could - oh, I don't know - use the stuff built into the OS and do something more productive with your time.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
If you mean system wide, then develop your own screensaver project and use the system's screensaver settings to set the various delay settings etc.
If you mean you want a screensaver within you application's form only to be activated after your app has been inactive - have a look at my Application Idle[^] article.
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 want to get some data from my database... but i get this error. It worked on my other form... but i get an error on this one. What could be wrong?
-------------------------
<br />
string DelalUR="" ;<br />
double ZasluzekUre=0;<br />
string izmena="";<br />
double ZasluzekVsota=0;<br />
string Skener="";<br />
string podstavka="";<br />
<br />
<br />
<br />
if (izbrano)
{<br />
<br />
DateTime start = new DateTime(prihodDat.Value.Year, prihodDat.Value.Month, prihodDat.Value.Day, (int)prihodH.Value, (int)prihodM.Value, 0);<br />
DateTime entry = new DateTime(odhodDat.Value.Year, odhodDat.Value.Month, odhodDat.Value.Day, (int)odhodH.Value, (int)odhodM.Value, 0);<br />
<br />
TimeSpan cas = entry - start;<br />
<br />
DelalUR = cas.Hours.ToString() + ":" + cas.Minutes.ToString();<br />
ZasluzekUre = cas.TotalMinutes / 60;<br />
<br />
if (rDopoldanska.Checked)<br />
izmena = "Dopoldanska";<br />
if (rPopoldanska.Checked)<br />
izmena = "Popoldanska";<br />
if (rNocna.Checked)<br />
izmena = "Nocna";<br />
<br />
if (radioButton1.Checked)<br />
Skener = "OCR";<br />
if (radioButton2.Checked)<br />
Skener = "Skener";<br />
<br />
<br />
<br />
string sqlCommSkeniranje = "SELECT Podstavka FROM Skeniranje WHERE Izmena = '" + izmena + "'";<br />
string sqlCommSkladisce = "SELECT Podstavka FROM Skladisce WHERE Izmena = '" + izmena + "'";<br />
string sqlCommZlaganje = "SELECT Podstavka FROM ZlaganjeDokumentov WHERE Izmena = '" + izmena + "'";<br />
string sqlComm="";<br />
OleDbConnection dbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:\\baza.mdb");<br />
<br />
if (comboDelovno.Text == "Skeniranje")<br />
sqlComm = sqlCommSkeniranje;<br />
if (comboDelovno.Text == "Skladišče")<br />
sqlComm = sqlCommSkladisce;<br />
if (comboDelovno.Text == "Zlaganje Dokumentov")<br />
sqlComm = sqlCommZlaganje;<br />
<br />
OleDbCommand dbComm = new OleDbCommand(sqlComm, dbConn);<br />
<br />
dbConn.Open();<br />
OleDbDataReader beri = dbComm.ExecuteReader();<br />
beri.Read();
podstavka = Convert.ToString(beri.GetString(0));
dbConn.Close();<br />
----------------------------------
The error report from JIT debugger
************** Exception Text **************
System.InvalidCastException: Specified cast is not valid.
at System.Data.OleDb.ColumnBinding.ValueString()
at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
at Osnova_za_studentske_ure.frmUporabnik.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\milos\My Documents\Visual Studio 2008\Projects\Osnova za studentske ure\Osnova za studentske ure\frmUporabnik.cs:line 153
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
Osnova za studentske ure
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
Accessibility
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:----------------------------------------
System.Data.DataSetExtensions
Assembly Version: 3.5.0.0
Win32 Version: 3.5.21022.8 built by: RTM
CodeBase: file:----------------------------------------
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.21022.8 built by: RTM
CodeBase: file:----------------------------------------
Sorry for my bad english... but i hope you understand what i'm trying to say.
Thanks for your answers in advance!
Regards,
Matjaž
Força Barça!
|
|
|
|
|
First of all, use parametrized queries instead of string concatenation: Parametrized Queries VS String Concatenation[^]
Secondly, exception occurs at podstavka = Convert.ToString(beri.GetString(0));
As GetString() returns string calling Convert.ToString() is extra. Check that the value that the datareader hold is really a string or just access it like this:
podstavka = beri[0].ToString();
|
|
|
|
|
Great. It worked! Dont know why it worked like .GetString(0) here, cus it worked on the other form... but i dont care that much
Anyway... about the injections - yes, i'm aware of that... and i'm planing to put some restrictions in the input of the user, so there's no worries. At least not in this project.
Thanks again!
Regards,
Matjaž
Força Barça!
|
|
|
|
|
Glad to help you Injections aren't the only reason to use parametrized queries. Even if you put restriction on input it is still better to have one more mechanism against possible attacks.
|
|
|
|
|
Hi there,
I'm looking to create a small Multiple Choice Exam for a side project of mine. For each question I would like there to be a text question, then a selection of four answers. The user then could submit his answer and after say 10 questions his score could be produced (you get the picture :P).
Anyway I'm actually after some advise as to how to implement this. Which technique do you think I should use to store questions and answers? Database, XML, text files? Could anyone give me any tips on how to do this?
Thanks in advance,
Tim.
|
|
|
|
|
Smells like a homework assignment to me...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
you're half wolf or something?
Code? Yeah i love it fried together with a glass of wine.
|
|
|
|
|
TimmyC1983 wrote: Database, XML, text files?
Whatever you use, I think you should encrypt your file using one of existing Cryptographic algorithms[^].
Life is 5: 3 me, 1 you.
|
|
|
|
|
Hi,
I am trying to bring generic weak reference dictionary in c# 3.0. I have created a class called WeakDictionary<TKey, TValue> which implements IDictionary<TKey,TValue>. This class has a private member as,
private Dictionary<TKey, WeakReference> weakDictionary = new Dictionary<TKey, WeakReference>();
The other methods like Add,Remove, Clear are working fine for the weakDictionary. But I could not work out the TryGetValue method. It shows the error InvalidCastException was unhandled - Unable to cast object of type 'System.WeakReference' to type 'System.String'. on the line
value = (TValue)weakReference.Target;
I don't know how to retrieve the value. Please help me.
CODE
public bool TryGetValue(TKey key, out TValue value) {
WeakReference weakReference;
if (this.weakDictionary.TryGetValue(key, out weakReference) && weakReference.IsAlive) {
value = (TValue)weakReference.Target;
return true;
} else {
weakDictionary.Remove(key);
value = default(TValue);
return false;
}
}
Thank you.
|
|
|
|
|
It seams that your weak reference is referencing another weak reference, not a string.
I would make a WeakReference<T> class to wrap the weak reference in a type safe way. That way you don't get in that kind of situation.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Beat me to it.
Guffa wrote: I would make a WeakReference<t> class to wrap the weak reference in a type safe way. That way you don't get in that kind of situation.
Yeah, good call. Do this Seetha.R.
Simon
|
|
|
|
|
Thank you Simon, the wrapper class concept worked well....
|
|
|
|
|
Thank you very much Guffa.....It worked.....
|
|
|
|
|
It looks like you've somehow got confused and stored a weak reference to a weak reference. I'd double check your Add() code, and make sure you're only storing a weak reference to a string and not a weakreference to a weakreference to a string.
Simon
|
|
|
|
|
i need a full list of naming conventions for all controls in c#, including workflow activities!
|
|
|
|
|
|
Member 2069064 wrote: i need a full list of naming conventions for all controls in c#, including workflow activities!
Dont type in bold, there is nothing to emphasize here.
Well, naming conventions vary from Organization/Groups. The primary goal of having them is to make the code look as it was written by one developer i.e. readable and easy to understand.
Though you can find general conventions here[^].
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
|
Yessir, of course sir, I will look into it right away sir!
..wait, I don't work for you, do I?
|
|
|
|
|
I need a shed load of wonga, but I don't expect to get an answer to it here.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I am writing a class that wraps and helps me deal with calls to an external c++ library from C#. My class is used in a webservice environment, so must be sensitive to the multi-threaded nature of web requests, however I dont think the c++ library was ever written with this in mind so I must be careful how I call it.
To simpify things the C++ library has a few methods I must call
Init - must be called only once, the first time my class is used
SendData - used to start a communication
ReceiveEvent - must be called on a timer with a short interval, used for receiving events back from the external library (and I use it to raise events in my class)
ShutDown - must be called once before the application exits
Now this structure I think lends itself to a Singleton which takes care of the Init/Shutdown, and a factory method to create my instance of a "Call". Feel free to suggest another approach if you think im wrong there.
The problem im having is in ensuring that "Init" has been called before any other thread manages to call SendData. eg
Thread1 calls SingletonObject.Instance.CreateCall() - this starts the processof calling "Init"
Thread2 calls SingletonObject.Instance.CreateCall() - however as Init has not yet completed this fails
I have tried all sorts of variations of lock() and Mutex, but im not seeing the behaviour I expect. Here is some cut-down code which will hopefully demonstrate what im attempting (Methods prefixxed "X25" are the external calls). Any help appreciated as always.
public class Xot
{
#region Static
static Xot()
{
}
private static readonly Xot instance = new Xot();
public static Xot Instance { get { return instance; } }
#endregion
private Dictionary<int,> calls;
private bool initialised = false;
private Timer waitTimer;
private Xot()
{
calls = new Dictionary<int,>();
waitTimer = new Timer(this.ReadEvents, null, Timeout.Infinite, Timeout.Infinite);
Console.WriteLine("Initialising Xot");
if (!this.initialised)
{
lock (Xot.Instance)
{
int rc = X25.HsX25DllInit(
"10.80.105.102",
0,
1024,
2,
1,
4095,
1);
if (rc == X25.HSX25DLL_RC_OK)
{
initialised = true;
this.waitTimer.Change(0, 15);
}
else
{
throw new Exception(String.Format("Failed to initialised Xot. RC={0}", rc));
}
}
}
}
~Xot()
{
if (this.initialised)
{
Console.WriteLine("Shutting Down Xot");
int rc = X25.HsX25DllShutDown(0);
if (rc != X25.HSX25DLL_RC_OK)
{
throw new Exception(String.Format("Failed to shut down X25 [RC={0}]", rc));
}
this.waitTimer.Change(Timeout.Infinite, Timeout.Infinite);
this.initialised = false;
}
}
private void CheckInit()
{
if (!this.initialised)
throw new InvalidOperationException("Not initialised");
}
public XotCall CreateCall()
{
this.CheckInit();
XotCall call = new XotCall(this);
return call;
}
}
|
|
|
|
|
Just a couple of comments:
1) Your lock and if statement are backwards. 2 threads could get past the if statement. One would pass the lock and do the init, the other would hang at the lock. When the first exited the lock, the second would then be released and pass the lock and do the init again.
2) I wouldn't lock on the instance. Mainly because it's public (advised against). If you must use a lock, create a private lock object instead.
3) I wouldn't put the shut down code in a finaliser. Finalisers aren't guaranteed to be run, and if a finaliser blocks or throws an exception it can screw up your garbage collector thread - You definitely shouldn't be throwing exceptions from a finaliser, it will kill the garbage collector, and the exception will never get reported. I'd do it with a dispose pattern (and put the code inside the if block so it's only called when disposing and not when finalising) and make sure you call dispose manually from your applications shutdown routines.
4) It's a singleton. That means the constructor only gets called once. You've used a thread safe singleton patten, so unless I've missed something I think you don't need the initialised flag or the lock at all. Just ditch the lock and flag entirely and trust the singleton pattern to only create the object and call the constructor once.
Simon
|
|
|
|
|