|
the ref keyword forces the argument to be passed by reference, it has no effect on reference types such as DataRow, but consider the following example with a value type:
static void Main()
{
int i = 1;
NoRef(i);
Console.WriteLine(i);
WithRef(ref i);
Console.WriteLine(i);
}
static void NoRef(int i)
{
i = i +1;
}
static void WithRef(ref int i)
{
i = i + 1;
}
as for the out keyword, this means that the method itself has to set the value of the param before using it. Hence why you cant check it for null before initializing it to some value.
static void Main()
{
int i = 0;
SetOut(out i);
Console.WriteLine(i);
}
static vouid SetOut(out int i)
{
i = 1;
}
So to cut a long story short, just remove the out/ref keyword altogether from your method. You can still change the values of your DataRow within your method.
|
|
|
|
|
Hello,
I want to develop small application for Desktop Sharing if you provide me any example or any link will be good for me.
Thanks
Best Regards,
Chetan Patel
|
|
|
|
|
Look at the source code of VNC, I am sure that will scare you off, as this is no small feat.
|
|
|
|
|
i planning to create a web base vb script editor by c#
but i have no idea about this....
have any suggestion how to create it??
can i apply msscript.ocx for this editor?
|
|
|
|
|
how to insert float value from string into sql from C# .net in float column in database. It should accept only the given decimal point.
Ashok
|
|
|
|
|
Hello Ashok,
If I get it correctly, you wish to retrieve a value from a string variable
containing a floating value. If thats the case, you can try this.
String str = "123.32";
float f = float.Parse(str);
I hope this helps.
Regards,
Allen
Allen Smith
ComponentOne LLC
www.componentone.com
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace TestApplication
{
public partial class Form1 : Form
{
progress prg = new progress();// this is a form
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(loop));
t.Start();
}
public void loop()
{
showProgress();
for (long i = 0; i < 500000000; i++)
{
}
this.BeginInvoke(new MethodInvoker(showC));
}
public void showProgress()
{
//if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(showP));
}
}
public void showP()
{
prg.ShowDialog();
}
public void showC()
{
prg.Close();
}
}
}
|
|
|
|
|
You need to show the progress window until the "Loop" finishes, right ? Then your code is wrong. prg.ShowDialog() in the "Loop" method blocks the current thread, which means your loop won't get executed until the progress closes.
Show the progress from the main thread and execute the "Loop" method in the thread which you created. Something like
private void button1_Click(object sender, EventArgs e) {
progress prg = new progress();
Thread t = new Thread(new ParameterizedThreadStart(loop));
t.Start(prg);
prg.ShowDialog();
}
delegate void ProgressCloseInvoker(progress prg);
public void loop(object obj) {
progress prg = obj as progress;
for (long i = 0; i < 500000000; i++) {
}
this.BeginInvoke(new ProgressCloseInvoker(CloseProgress), prg);
}
public void CloseProgress(progress prg) {
prg.Close();
}
|
|
|
|
|
N a v a n e e t h wrote: prg.ShowDialog() in the "Loop" method blocks the current thread, which means your loop won't get executed until the progress closes.
Not really, the OP is using BeginInvoke, which pushes the delegate to the UI thread and returns immediately.
|
|
|
|
|
S. Senthil Kumar wrote: the OP is using BeginInvoke
Ohh I didn't noticed that. Thanks for pointing it
|
|
|
|
|
Senthil, i have read you article and then implemented this program
http://www.codeproject.com/KB/cpp/begininvoke.aspx[^]
But what does the exactly invokerequired() do does it checks whether message is posted in message queue if it is posted then it returns true or false.
Clear me
|
|
|
|
|
I didn't noticed BeginInvoke on your sample, your code is correct then. As you are showing the progress as modal, there is no chance of clicking the button for one more thread to create. So there won't be any thread safety issues, AFAIK.
|
|
|
|
|
Senthil, i have read you article and then implemented this program
http://www.codeproject.com/KB/cpp/begininvoke.aspx[^]
But what does the exactly invokerequired() do does it checks whether message is posted in message queue if it is posted then it returns true or false.
Clear me
modified on Monday, July 21, 2008 3:57 AM
|
|
|
|
|
Mogaambo wrote: But what does the exactly invokerequired
InvokeRequired checks whether the current thread is the thread that created the control on which InvokeRequired is being called.
|
|
|
|
|
ok then y it gives 1 time true then false according to your program, it should always give false value as this thread doesn't created it.
|
|
|
|
|
If you looked at the code carefully, you would have noticed that the if (InvokeRequired) block actually passes the current method as the parameter to Invoke/BeginInvoke. The current method will therefore get called again, but this time on the UI thread, as it was passed as the delegate to Invoke/BeginInvoke, and InvokeRequired will therefore return false.
|
|
|
|
|
but this time on the UI thread
|
|
|
|
|
You do understand what Invoke or BeginInvoke does, don't you? They help you execute the delegate, that you pass as the parameter, on the UI thread. Invoke will wait until the delegate completes, BeginInvoke simply posts it to the UI message queue and returns.
Either way, the UI thread executes the delegate - this is the "second time" that you are talking about. InvokeRequired will obviously be false, since it's the UI thread that created the control on which InvokeRequired is called.
|
|
|
|
|
Hello everyone,
I am writing an Http client. Any samples for dealing with Http authentication? e.g. https, certificate?
thanks in advance,
George
|
|
|
|
|
George_George wrote: Http authentication
I hopr you are using HttpWebRequest class. You can set the credentials to Credentials[^] property. Something like
HttpWebRequest request = WebRequest.Create(new Uri("http://somewebsite.com"));
request.Credentials = new NetworkCredential("username", "password");
|
|
|
|
|
Thanks N a v a n e e t h,
Your sample contains information about how to apply user name and password as authentication information. And also how to use the default certificate.
My question is, if the web site has some customized certificate, or the end user (e.g. my Http client) has some customized certificate, are there any samples about how to deal with it?
regards,
George
|
|
|
|
|
George_George wrote: if the web site has some customized certificate, or the end user (e.g. my Http client) has some customized certificate,
I don't know. Are you getting any error when you try to connect to a URL which has customized certificate ?
|
|
|
|
|
Thanks N a v a n e e t h,
My situation is, I have some installed certificate in IE for either web site or my personal certificate, and they are used to either access some special web site or identify for myself.
For the Http client application, I want to utilize them to access the special web site. Any ideas or reference samples?
regards,
George
|
|
|
|
|
Hey, guys.
Got a winforms / c# app that uses the webbrowser control to navigate to and then save off a screen capture of the given web site. Unfortunately, trying to run this in a batch is proving fruitless as the control throws up IE's various dialog boxes complaining of this or that, e.g. script error, unrecognized publisher, etc. Quite a few instances with different dialog / message boxes, and of course program execution comes to a halt until a human clicks OK, rendering it a bit useless for overnight batch processing.
I've played with all the options in IE, as well as the properties on the webbrowser control, to no avail. In fact, when I do something like disabling all downloadable content (activex controls, etc.), they do indeed get suppressed. Then IE gives me a dialog box complaining that it can't render the page properly because it the controls weren't downloaded!
Does anyone know how to rig this control to run in silent mode and suppress all Windows / IE dialog boxes and error messages? Or a different c# compatible approach to accomplishing the screen shots? I'd be most grateful for any enlightenment.
Thanks,
|
|
|
|
|
You dont mention specific names, so I will ask:
ScriptErrorsSuppressed = true ?
|
|
|
|