|
Hi
I began writing a c# program and everything was going ok until i tried to use asynchronous webrequests instead of synchronous ones (since the UI would be unresponsive while it was fetching the response) and i have a slight problem:
the user signs in by clicking a button on the form - the program fetches the data from the server asynchronously - the problem is with the callback function - when debugging i see that the request was successfully completed but when i try to access any controls (like filling a textbox with the response) from the callback function it just stop executing the function - no exceptions, no errors - i can still interact with the program but it just wont alter anything to do with the form's controls (the form's data members however were being altered with no issues - a string and an integer to be exact)
I'm a newbie at c# and i just started using the asynchronous method so if im doing sumthing wrong please advise
thank you for your time
|
|
|
|
|
A good first step would be to post some code, so we can offer some advice on it.
Christian Graus - C++ MVP
|
|
|
|
|
Hi
thanks for your quick reply
these are methods of my MainForm class (base class is Form)
<br />
private void getResult(String url, AsyncCallback callback)<br />
{<br />
try<br />
{<br />
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);<br />
request.Method = "GET";<br />
if(useCompression)<br />
request.Headers.Add("Accept-Encoding: gzip,deflate");<br />
request.CookieContainer = mainCookie;<br />
request.AllowAutoRedirect = true;<br />
request.AllowWriteStreamBuffering = true;<br />
<br />
IAsyncResult result = request.BeginGetResponse(callback, request);<br />
}<br />
catch (WebException wex)<br />
{<br />
MessageBox.Show("Error Connecting: Check your connection settings...\nDetails: " + wex.Status.ToString());<br />
return;<br />
}<br />
}
<br />
private void SignInButton_Click(object sender, EventArgs e)<br />
{<br />
DisableSignInControls();<br />
String url = mirror + "signin.aspx?user=" + UserNameComboBox.Text + "&pass=" + PasswordTextBox.Text;<br />
mainCookie = new CookieContainer();<br />
getResult(url, new AsyncCallback(signIn));<br />
}<br />
<br />
<br />
private void signIn(IAsyncResult result)<br />
{<br />
HttpWebRequest request = (HttpWebRequest)result.AsyncState;<br />
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);<br />
String responseResult = (useCompression ? decompressResponse(response) : new StreamReader(response.GetResponseStream()).ReadToEnd());<br />
int i = responseResult.IndexOf("<response>");<br />
if (i < 0)<br />
MessageBox.Show("Corrupt response. Please try again.");<br />
else<br />
{<br />
int j = responseResult.IndexOf("</response>");<br />
String temp = responseResult.Substring(i + 10, j - i - 10);<br />
if (temp != "")<br />
{<br />
String[] returnValues = temp.Split('|');<br />
if (returnValues.Length == 1)<br />
MessageBox.Show(returnValues[0]);<br />
else<br />
{<br />
sid = returnValues[0];<br />
num_messages = int.Parse(returnValues[1]);<br />
MessageNumber.Text = "Messages: Left " + num_messages;<br />
SignInGroupBox.Visible = false;<br />
SendSMSGroupBox.Visible = true;<br />
SignOutMenu.Visible = true;<br />
FillContacts();<br />
}<br />
}<br />
}<br />
EnableSignInControls();<br />
FillUsers();<br />
}<br />
the other functions are also part of the mainform class and they all make changes to the controls on the form.
do you need more info?
thanks again.
|
|
|
|
|
wajih.boukaram wrote: IAsyncResult result = request.BeginGetResponse(callback, request);
Doesn't result just get discarded ? And where is the callback hooked up to a method ?
Christian Graus - C++ MVP
|
|
|
|
|
yea it does but all that matters is the callback function (which i assigned when i called getResult(url, new AsyncCallback(signIn));
so its hooked up to signIn
it works fine the way it is - only problem is changing the form's control values - i think it might have something to do with threading because if i try calling the function a second time (I hate c# sometimes) it says sumthin about accessing an object that was not created on the same thread - when i first tried to do this asynchronously i actually just created a new thread that called my initial signIn function which was just a regular function and not a callback - i got the same error message when acessing the controls.
any suggestions?
thanks for your replies.
|
|
|
|
|
I was just wondering if anyone has managed to create a C# object that is exposed as a COM object and successfully insert it into the Running Obhect Table (ROT). Just as important, once in the table have you been able to extract it and actually call a method on it.
To test this, I have created two projects. The first one creates the C# object and inserts in into the ROT. It then waits until cancelled. The second one attempts to retrieve the object from the ROT. The second project contains a reference to the dll that contains the C# object created in the first project.
I believe I can successfully insert the object into the Running Object Table. As I can see the object in the ROT if I dump the contents.
When I try to access the entry, I seem to be able to pull it out of the table. But when I try to bind to the object
<br />
iMoniker.BindToObject(ctx, iMoniker, ref IID_ICancelAutoplay, out o);<br />
I get a "System.IO.FileNotFoundException" indicating "The specified module could not be found (Exception from HRESULT:0x8007007e)".
Any thoughts, hints would be greatly apreciated. I'd even be willing to be spoon feed on this one.
Thanks
Tim
|
|
|
|
|
Hi all,
I'm currently making an application for graphical manipulation of data. (i.e. a graph) Due to the interaction requirements I've used opengl to do the rendering due to its great speed. The problem I'm having is concerning the rendering strings/fonts.
I'm currently using the Tao libraries and the glutBitmapString function to render my text which has sufficed until now. On the Y axis of the graph I need to be able to render the text of the axis label vertically, as is common. Yet I cannot find anything to do this.
I've looked at the NeHe tutorials about rendering fonts, but they seem to be all in C++ and I cant find anything that will work in C#.
Does anyone have any ideas of how I go about doing this? I'd really appriciate any help at this point as currently I'm at a total loss.
|
|
|
|
|
Does glRotatef( -90, 0, 0, 1) (or whatever the Tao equivalent is) before calling glutBitmapString work?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
No, unfortunately not. I don't think that glutBitmapString has the ability to render text at any angle. I've looked for an alternative font library, but I either can't find a suitable one, or they are not created for use in C#
Edit: I've also tried using the glutStrokeString function, but I cant get this to render anything at all.
-- modified at 6:55 Thursday 16th November, 2006
|
|
|
|
|
hi
i want to get position of my datarow in dataset, How to do that ??
i am using vC# 2005
thanks
|
|
|
|
|
Well, a DataSet doesn't contain rows directly. Rather, it contains DataTables, which then contain rows. To find a row in a table in a dataset, you need to iterate over all the DataTable objectss, then look for the row in each table. Something like this:
int GetIndexOfRow(DataSet dataSet, DataRow row)
{
foreach(DataTable table in dataSet.Tables)
{
int index = table.Rows.IndexOf(row);
if(index != -1)
{
return index;
}
}
return -1;
}
|
|
|
|
|
I am displaying blocks of text in a datagridview control. The column is setup to not wrap or size. The first x characters are shown and then truncated. Since the column type is string, the datagridview shows the entire cell contents in a tooltip. Is there a way to control the font of this default behavior? I just need to increase the font size from what looks to be 10pt to 12pt or 14pt.
Any information would be greatly appreciated.
Steve
|
|
|
|
|
Did you find the solution....? I am also stuck in the same problem.
dfdfd
|
|
|
|
|
I downloaded the 'Building a Data Access Layer - The Demo Application' by Damon Armstrong. I want to use the DataServiceBase class that he built in another application. I do not want to use the PersonDataService that he has in the same Namespace. To make a long story short, I copied the class that I want to a new C# Class Library. There is only one problem, it won't compile. I get the following error:
The name 'ConfigurationManager' does not exist in the current context C:\HAA_C_Library\DataServiceBase\DataServiceBase.cs
Here is the method that causes the error:
protected static string GetConnectionString()
{
return ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
}
I have the following before the start of the class:
using System.Configuration;
When I go to the Object Browser, it shows ConfigurationManager as a class within System.Configuration. Yet, when I try to use it; it is not there. When I go to the original code that I downloaded, it behaves as desired.
What is happening here? I've looked at everything I know to look at and can't see any difference between the original code and mine. But one works and one doesn't.
Thanks in advance,
Mary
|
|
|
|
|
Well, after trying almost everything. I got it to work. I added System.Configuration to the References section. Now all is fine. Evidently, it was not using the correct library.
|
|
|
|
|
No, you were using the correct library you just hadn't told the compiler to link it in, so although it was importing the System.Configuration namespace it couldn't actually find it.
|
|
|
|
|
i wanna to know how can i generate an algorithm by using DNA computing to solve A/B problem? is it NP complete?
SUMA
|
|
|
|
|
bool isA = false;
bool isB = false;
foreach (chromosome c in theCell)
foreach (gene g in c)
{
if (g == KnownGenes.BloodTypes.A)
isA = true;
if (g == KnownGenes.BloodTypes.B)
isB = true;
}
if (isA && isB)
printf("type AB");
else if (isA)
printf("type A");
else if ( isB)
printf("type B");
else printf("type O");
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
thanks alot for reply, is there a way to proof that a\b is a NP complete or not?? using hamitolian path for example?is their such algorithm for that??
SUMA
|
|
|
|
|
|
i didnt mean that,, i wanna to know if there any resources of what i need couse i searched but i didnt find any good result, & if u familiar of these kind of problem u know that it is just the first step
thx
SUMA
|
|
|
|
|
Harta hr = this.ParentForm;
hr.OnPaint1();
this code raises the folowing error
Error 1 Cannot implicitly convert type 'System.Windows.Forms.Form' to 'THE_PROJECT.Harta'. An explicit conversion exists (are you missing a cast?) C:\Documents and Settings\Razvan\My Documents\Visual Studio 2005\Projects\THE PROJECT v2\THE PROJECT v2\Elemente.cs 48 23 THE PROJECT v2
i knew it was imposible for that to work but i need to call that method from the child form. Can somebody help me?
rzvme
|
|
|
|
|
Harta hr = this.ParentForm as Harta;<br />
if (hr != null) hr.OnPaint1();
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
The method that Pete mentions is valid. However, I would suggest you look at having the child form raise an event that the parent form subscribes to.
public class MainForm : Form<br />
{<br />
public void CreateChild()<br />
{<br />
ChildForm cForm = new ChildForm();<br />
cForm.ParentForm = this;<br />
cForm.MyOnPaint += new EventHandler(OnPaint1);<br />
<br />
cForm.Show(); <br />
}<br />
<br />
protected override void OnPaint1(object sender, EventArgs e)<br />
{<br />
}<br />
}<br />
<br />
public class ChildForm : Form<br />
{<br />
public event EventHandler MyEvent;<br />
<br />
protected override void OnMyEvent(object sender, EventArgs e)<br />
{<br />
if (MyEvent != null)<br />
MyEvent(sender, e);<br />
}<br />
}
Please forgive any typos as I wrote the above code on-the-fly. So, in the child form when something happens that you want to communicate back the event you just call OnMyEvent from within the ChildForm. The nice thing about this is that it promotes loose coupling, because the ChildForm doesn't know if it's parent is MainForm or SomeOtherForm. You can take it a step further by making the event part of an interface that ChildForm implements. In that way you decouple the child from the parent as well.
|
|
|
|
|
How can you find a datareader is open or closed ?
|
|
|
|