|
Well Im completly agree with PIEBALDconsult.
Use either dictionary or hashtable object to store all parameters as key, value pair.
This will be much easier to maintain as well as you have only one public variable.
|
|
|
|
|
how can I have the hashtable as public? I tried the following but not working!
my public class is:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace cure_hospital_management
{
class public_class
{
private Hashtable _sysem_parameters;
public Hashtable sysem_parameters
{
get { return _sysem_parameters; }
set { _sysem_parameters = value; }
}
}
}
my code in the mail form load is:
<pre>public_class public_var = new public_class();
private void get_system_parameters2()
{
public_var.sysem_parameters = new Hashtable();
public_var.sysem_parameters.Add("Name", "Jassim Rahma");
}
</pre>
and my code to read the value is:
<pre>MessageBox.Show((string)public_var.sysem_parameters["Name"]);</pre>
but I am getting this error when reading the value:
Object reference not set to an instance of an object.
|
|
|
|
|
u need to call get_system_parameters2() before accessing hashtable.
First follow some guidlines to make it more perfect
1. Move sysem_parameters = new Hashtable(); in public_class class.
2. Check if hasttable is null then create new instance of hasttable in get part of sysem_parameters.
3. Have a look at Singleton pattern
|
|
|
|
|
how can I keep one sql connection alive in my application and use that connection in my all forms? and does it have any disadvantages?
|
|
|
|
|
Your application shouldn't know anything about the database.
Your application should have a business layer. You can pass a reference to the business layer to each form, then they can each use it.
|
|
|
|
|
so you mean i should open and close the connection in every form?
|
|
|
|
|
Yes, inside the Data Access Layer, the connection would be opened and closed for each operation.
And watch out for threading issues.
|
|
|
|
|
Usually, you open and close the connection on every operation. You don't keep a connection open for the life of a form or for an entire applications lifetime. SQL Server (or other) licenses are expensive and connections consume resources on both the client and server side. You grab a connection, use it, then release it when your operation is complete.
Again, you UI code should have nothing to do with the database connection at all. That is up to your business and data layers.
|
|
|
|
|
No it does not have an advantage, it could in fact be a severe disadvantage. If you are concerned about performance, then as PIEBALD has said, use a business layer that could potentially cache data.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Keeping SQL connection alive is a bad idea. Usual pattern for using SQL connection is to open it, execute the SQL and close it. ADO.NET has connection pooling built in and creating a new instance of SQL connection can return from pooled objects.
What are you trying to achieve by keeping the connection alive?
Best wishes,
Navaneeth
|
|
|
|
|
How can I make a specific printer a default printer for my application regardless of the windows default printer so the user will always print to the application printer without making the user to choose which printer to print on?
|
|
|
|
|
You need to use the PrintDocument class in a manner similar to the following:
PrintDocument prndoc = new PrintDocument();
prndoc.DocumentName = "My document";
prndoc.PrintPage += new PrintPageEventHandler(PrnPage);
prndoc.PrinterSettings.PrinterName = strPreferredPrinter;
prndoc.PrinterSettings.DefaultPageSettings.Landscape = true;
prndoc.DefaultPageSettings.Landscape = true;
prndoc.Print();
Every time the program runs, it should check to see if the preferred printer is still available. This is done by something like this:
PrinterSettings ps = new PrinterSettings();
ps.PrinterName = strPreferredPrinter;
if (! ps.IsValid) {
ps = new PrinterSettings();
strPreferredPrinter = ps.PrinterName;
}
Hope this helps. Happy programming!
modified on Friday, April 9, 2010 2:16 PM
|
|
|
|
|
Hello,
I'm trying to make an application in C# that will connect to a web cam, show the video stream and then draw text over the video. I have search countless hours and found an example using directshow that put texts over video that is being played from a file, but not from a live video stream from a web cam. Does anyone know how this can be done with a web cam or know where I could find any examples?
|
|
|
|
|
i´m trying to make a web form to do auto -login in a web game but the login page don't have a click button but have a input type ="image"
Code from the web page:
<div style ="height:180px;padding-top:36px;" >
<form action ="index.php?ac=loginpage" method ="post" style ="margin:0px;padding:0px;" onsubmit ="esvtk_track( {esvtk_v:'1',
esvtk_esvid:'A10050' , event:'reg_monstersgame', amount:'1'});" >
<div >
<table width ="100%" style ="text-align:left;" >
<tr >
<td >
servidor:
</td >
<td >
<select name ="server" onchange ="javascript:location.href=this.value;" size ="1" class ="input" >
<option value ="http://www.monstersgame.com.pt/?ac=loginpage" > World 1</option >
<option value ="http://world2.monstersgame.com.pt/?ac=loginpage" > World 2</option >
<option value ="http://world3.monstersgame.com.pt/?ac=loginpage" > World 3</option >
<option value ="http://world4.monstersgame.com.pt/?ac=loginpage" > World 4</option >
<option value ="http://world5.monstersgame.com.pt/?ac=loginpage" > World 5</option >
<option value ="http://world6.monstersgame.com.pt/?ac=loginpage" > World 6</option>
<option value ="http://world7.monstersgame.com.pt/?ac=loginpage" > World 7</option >
<option value ="http://world8.monstersgame.com.pt/?ac=loginpage" > World 8</option >
<option value ="http://world9.monstersgame.com.pt/?ac=loginpage" > World 9</option >
<option value ="http://world10.monstersgame.com.pt/?ac=loginpage" selected ="selected" > World 10</option>
</select >
</td >
</tr >
<tr >
<td >
Nome:
</td >
<td > <input type ="text" name ="user" size ="30" style ="width:170px;" /> </td >
</tr >
<tr >
<td >
Senha:
</td >
<td > <input type ="password" name ="password" size ="30" style ="width:170px;" /> </td >
</tr >
<tr >
<td colspan ="2" style ="text-align:center;" >
<input type ="checkbox" name ="gfxpack" value ="1" style ="background:none;" /> Carregar imagens do servidor
<input type ="image" src ="img/teaser/EN/teaser_btn_verwandeln.jpg" alt ="Transformar" title ="Transformar" />
i can put the user name and the password but i can't send this information to the server
if some one could help me i will apreciate
|
|
|
|
|
Are you trying to submit the form while clicking image button?where you are validating username and password?
tedyboy9 wrote: onsubmit ="esvtk_track( {esvtk_v:'1',
esvtk_esvid:'A10050' , event:'reg_monstersgame', amount:'1'});"
what's this method actually do?Check if that method is suppressing the submit.
|
|
|
|
|
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("user").SetAttribute("value", textBox3.Text);
webBrowser1.Document.GetElementById("password").SetAttribute("value", textBox4.Text);
}
you see i can get this elements from the web page and i set his attributes , when i make login there are a image button in the web page , what i want is my web form make all this things to me
put username
put password
and click that image button for me to make the Auto-login
there is the link to the web game where i make login , you can see whow this works
http://world10.monstersgame.com.pt/[^]
thanks
|
|
|
|
|
Hey...
I need to implement 2 methods asynchronous methods, one for reading data, and one for writing...
the ManualResetEvent initialization is with false ManualResetEvent mre = new ManualResetEvent(false);
if i understand correct, it means that it'll be block the accessing thread till the set() will be executed.
what will happen if one thread will execute set(), and after it, other thread will execute WaitOne() before Reset was executed, it will be blocked, or the thread will continue running
I hope i was clear enough
Thanks
|
|
|
|
|
Hi,
the MSDN documentation on ManualResetEvent clearly states: "Once it has been signaled, ManualResetEvent remains signaled until it is manually reset. That is, calls to WaitOne return immediately."
|
|
|
|
|
If you are trying to effectively solve a producer/consumer problem, I would suggest looking into the Monitor class, particularly Monitor.Wait and Monitor.Pulse; in a typical producer/consumer situation, the consumer wants to check whether any data is available, and if not start waiting on an object without giving the producer a chance to add data and flag the object between the consumer's check and wait. While this sort of thing can be done with some WaitHandle objects, it's easier to use Monitor.Wait and Monitor.Pulse.
|
|
|
|
|
it's not a "producer/consumer problem"
and Monitor isn't good for me, it uses the object directly, and i don't have an access to it (private field in other class)
|
|
|
|
|
i wote next code
class SynchronizedMailBox : MailBox
{
private static ManualResetEvent mre = new ManualResetEvent(false);
private static Mutex mainMutex = new Mutex(false);
public override void Write(Message msg)
{
mainMutex.WaitOne();
if (IsEmpty())
mre.Set();
base.Write(msg);
mainMutex.ReleaseMutex();
}
public override Message Read()
{
mainMutex.WaitOne();
mre.WaitOne();
Message ms = base.Read();
if (IsEmpty())
mre.Reset();
mainMutex.ReleaseMutex();
return ms;
}
}
my question is, what will be happen when those lines will be executed
if (IsEmpty())
mre.Set();
and there are blocked thread/s on WaitOne() in read method.
the fact that write method is still under the mutex will prevent from unblocked reading thread/s to continue running ?
one more question is about if(isEmpty()) inside read method ,
do i need one more mutex to close the "if" or the main mutex which "close" the whole method is enough ?
tanks
|
|
|
|
|
|
igalep132 wrote: the fact that write method is still under the mutex will prevent from unblocked reading thread/s to continue running ?
If the 'reader' threads are sitting on MRE.WaitOne, how is the writer thread going to reach MRE.Set? Won't the writer thread me stuck at MainMutex.WaitOne since the reader thread will hold the mutex during Mre.WaitOne?
I would suggest that the best approach is to have the queue reader, if the queue is empty, reset MRE, leave the main mutex, and wait on MRE; the queue writer should set MRE unconditionally within the mutex. After every time the reader waits on MRE, it should re-check to see if the queue is empty; if not, it should re-loop.
It's tricky logic to get right, and I might have made a mistake in my description above; using the Monitor class will make things easier, but I think mutexes and manual-reset events should work.
|
|
|
|
|
Hi
I want to use one of the controls in the Code Project in a commercial appliction.
I read the license but I don't get the legal details.
I understood that I can use the control as long as I mention the copy right (or at least that is what I gathered).
My questions are:
1- Do I have to get permission from the author first to use his/her control or not?
2- Are there other obligations on me towards any other party?
Thanks much.
EK
|
|
|
|
|
ekareem wrote: 1- Do I have to get permission from the author first to use his/her control or not?
Ask the author, each article has an author and an associated license, which explains all legal recourse. If unsure, consult a lawyer
ekareem wrote: 2- Are there other obligations on me towards any other party?
Depends if the control uses any third party assemblies or code. You must check with a lawyer as any 'unmentioned' third party associations may still be at your own liability. Again, you can consult a lawyer as well as the author.
Always, always ask the author if you may use it in a commercial application and what you must do to do so. Get his/her answer in writing.
|
|
|
|