|
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.
|
|
|
|
|
Regardless of the legal issues I would say it's good manners to contact the author and certainly give credit where it is do.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
when using a delayed sign assembly where should be the public key in the client pc distributed by the owner organization
|
|
|
|
|
Hi there
I have searched a lot but I didn't find any thing
I want to know about 3 things!
1.How can we create a program like osk(on screen keyboard)that have focus on itself and other application in a same time
2.is it possible to run windows .net applications in windows before windows logon as a service?
3.is it possible to locate the application in a specific part of screen in C#
if you want to understand type magnify in run (in windows xp) to see wath I mean,it changes the screen resolution and runs on top of the screen where no other programs can run,maybe another desktop!
thanks
|
|
|
|
|
faslesabz wrote: How can we create a program like osk(on screen keyboard)that have focus on itself and other application in a same time
Learning how to search, part one[^]
faslesabz wrote: 2.is it possible to run windows .net applications in windows before windows logon as a service?
You can make .net services, no .net application can start before windows loads, included your service.
faslesabz wrote: is it possible to locate the application in a specific part of screen in C#
if you want to understand type magnify in run (in windows xp) to see wath I mean,it changes the screen resolution and runs on top of the screen where no other programs can run,maybe another desktop!
This is entirely way to confusing for me to understand. You can make your own magnification type program see; searching, part 2[^]
|
|
|
|
|
I have a WPF Window that at loading time generate a variable number of image with this for cycle :
public Window1()
{
InitializeComponent();
int numPos = 5;
for (int i = 1; i <= numPos; i++)
{
Image imageStatus = new Image();
imageStatus.Name = "Image" + i;
statusGrid.Children.Add(imageStatus);
}
}
Now i need to access at this image from a timer that every 10 seconds change the image.Source Property of every image crested at runtime ..
How Can i do this ?
|
|
|
|
|
Pick a forum and stick with it.
Don't just post this in the C# and WPF forums - it is clearly WPF so just post it there. Otherwise you will annoy people and reduce your chances of getting an answer anywhere...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|