|
To substantiate Leppie's post, when you call ShowDialog on a thread other than the UI thread, it essentially behaves as a modeless dialog. To do what you want, you have to make the call come from the UI thread, which you can do by calling Invoke[^] on the main form or any of the main form's controls. This will cause the delegate to be called from the UI thread and your form will be modal.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
e.g you have a method called ShowMyDialog(). You cannot call this method from another thread. Then you must use this code, if you want to call ShowMyDialog() from another thread :
MethodInvoker mInvoker = new MethodInvoker(ShowMyDialog);
Invoke(mInvoker);
|
|
|
|
|
Can ypu pls explain it with a simple example
Krishna
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace WindowsApplication5
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1()
{ InitializeComponent(); }
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{ components.Dispose(); }
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(48, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Change text";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(208, 189);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{ Application.Run(new Form1()); }
private void button1_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(CreateNewLabel));
t.Start();
}
private void CreateNewLabel()
{
MethodInvoker minvoker = new MethodInvoker(Run);
Invoke(minvoker);
}
private void Run()
{
try
{
Label label = new Label();
label.Name = "MyLabel";
label.Text = "MyLabel";
label.Location = new Point(50, 50);
this.Controls.Add(label);
}
catch(Exception ex)
{ MessageBox.Show(ex.ToString()); }
}
}
}
You cannot call method "Run" directly, because method "Run" is in another thread. That's why you must call the method CreateNewLabel to create a new label from another thread. You can find the complete description in : http://www.oreilly.de/catalog/csharpnutger/chapter/ch04.html
That site is in german, you can use www.google.com/translate to translate it in english.
|
|
|
|
|
I have user table.. (Uid, Uname, Upwd) , I need to authorize users like for each form. Im loging in like..
txtUserName + txtPwd->check for User exists in DB : login,Session["login"]=true, Session["UID"] else error,Session["login"]=false
simple...
But I dont want to checkup the Session varible in each form and see if the user can be allowed to view the page.
So I check up form authentication... I got this example...
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="30" path="/">
<credentials passwordFormat="Clear">
<user name="test1" password="test1" />
<user name="test2" password="test2" />
</credentials>
</forms>
</authentication>
here the user name and password are in the Web.config file..
There can be many users, so I cant put all of them here...
Is there a way?
_____________________________________________________
Yea! I could be wrong...
-- modified at 0:54 Thursday 18th May, 2006
|
|
|
|
|
U can pass userid and password as the querystring in a form having method attribute as post.
aashutosh tiwari
|
|
|
|
|
Pass it to each form?....
Well that would take checking it in each form just like the Session var.
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
saud_a_k wrote: Pass it to each form?....
It is also a security risk!
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Kakuji wrote: U can pass userid and password as the querystring
This is a very unwise idea.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
See these articles on MSDN for Forms Authentication with SQL Server: .NET 1.1[^] or .NET 2.0[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I know how to put in Usernames and passwords into sql table using the MD5,
What I'm askin' is, Ive got 3 folders with files in them
Admin folder - only admin has access (Whose user name an PWD are in SQL table)
client folder-only client and admin can access
Supervisor - only Supervisor and Admin can access
How do I do this stuff using web.config ?????
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
I have created new skin but when i am seeing it in my site portal skin it is not displying any name through which I can add that skin to my site. I need this as soon as possible.
aashutosh(aashutosh.tiwari@sakasolutions.com)
|
|
|
|
|
Better as this on the DNN forums, I doubt anyone in a C# Windows Forms forum will be able to help.
|
|
|
|
|
Hi
Can any one please tell me how to add the new rows to the existing table with the values using SqlAdapter and Data Row with out using insert statement.
DataSet dset = new DataSet("DBTable");
DataTable dbtable = new DataTable("DBTable"); dset.Tables.Add(dbtable);
SqlCommand dbcommand = new SqlCommand();
dbcommand.CommandText ="select * from DBTable";
dbcommand.Connection = myConnection;
SqlDataAdapter dbDA = new SqlDataAdapter(dbcommand);
dbDA.TableMappings.Add("Table", "DBTable");
dbDA.Fill(dset, "DBTable");
DataRow row;
row = dbtable.NewRow();
row["FileName"] = DBfile;
row["Meters"] = IMeter;
dbtable.Rows.Add(row);
dbDA.Update(dset);
This above code throws exception called "Update requires a valid InsertCommand when passed DataRow collection with new rows." any Idea?
|
|
|
|
|
You need to add a SqlCommand for INSERT to the SqlDataAdapter (you have already done so for SELECT, but passing it to the constructor).
|
|
|
|
|
if u want to update db with dataadapters update method
then u have to define adapters insert command with proper
parameters.
rahul
|
|
|
|
|
You should be replying to the original person asking the question
|
|
|
|
|
Has anyone worked on the concept of printing labels in microsoft word by taking c# as front end and access or excel as the back end...
Regards..
Amrit
|
|
|
|
|
Hi!
Can i send multiple files using the same tcp connection when using TCPClient and TCPListener classes!? I have made client and server part of app, and seems to me that everything is working fine on the server side, but when i try to send the second file through the same connection, i get the error:
"An unhandled exception of type System.InvalidOperationException' occurred in system.dll"
Additional information: Operation not allowed on non-connected sockets!
The code from client send button is:
...
private void buttonSend_Click(object sender, System.EventArgs e)
{
Stream fileStream = File.OpenRead(textBoxFile.Text);
byte[] fileBuffer = new byte[fileStream.Length];
fileStream.Read(fileBuffer,0,(int)fileStream.Length);
networkStream = soket.GetStream(); <- here rises the exception
networkStream.Write(fileBuffer,0,fileBuffer.GetLength(0));
networkStream.Close();
this.label2.Text = System.DateTime.Now;
}
...
When i erase the networkStream.Close(); line, i can send multiple files, but the network stream is never closed, so the file on the server side is always in use and i can`t do anything with it!
Thanx for help!
|
|
|
|
|
eyej wrote: Operation not allowed on non-connected sockets!
When you close the stream the underlying socket is closed. You could connect a second time to send the second file, or, you could introduce a protocol into the application that provides for sending two files.
Do you have any previous experience with TCP application protocols? If not you should read up on them. Some simple ones are SMTP and POP3.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
eyej wrote: networkStream.Close();
You should do that at some other stage, or reopen and close the TCP connection every time, it depends really on your requirements of the application what option you choose.
|
|
|
|
|
Well, i am trying to add a voice clip sending in my messenger app! Same as voice clip sending in MSN Messenger 7.5 and 8! So, it would not be a very good idea to make a new connection everytime a user would like to send a voice clip, because the TCP handshaking period is about couple of seconds and above! It would be much annoying for user to wait that time period!So.. i thought i could open one TCP connection when the application is starting, or when the user click "connect" button and send all voice clips through the same connection! Of course, in both directions! Any help please! How do you think this would be the best to do?
Thanks!
|
|
|
|
|
hi i want to embedd or bind any file to my app in runtime and extract it at run time again( for example i want that user can embedd or bind access db into my exe file or extract it again at run time) how to do that ??
codeproject is best ..
thanks
|
|
|
|
|
Would you explain it more. If you want the schema of an Access DB file then you can use OleDbSchemaGuid.
Saqib
|
|
|
|
|
no i don't want embedd only access db into my app, i want to embedd any file to my app or bind it to my app.(for example i want to bind an exe file to my app).
|
|
|
|