|
Why would you want to abort the thread? Why not make it exit normally using some event signalling mechanism?
That apart, what exactly does the thread do? If all it does is show a form, you're much better off doing it in the UI thread (the thread that Frm_Land_Load runs on) and doing this.Initialize_Data on a different thread. Something like
private void Frm_Land_Load(object sender, EventArgs e)
{
Thread th = new Thread(DoWork);
th.Start();
gu.Show_WaitingForm();
}
private void DoWork()
{
this.Initialize_Data();
this.BeginInvoke(new MethodInvoker(CloseWaitingForm), null);
}
private void CloseWaitingForm()
{
gu.Hide_WaitingForm();
}
This way, when Initialize_Data completes, CloseWaitingForm will be called on the main UI thread, which will hide the waiting form.
This solution assumes that Initialize_Data does not access any controls in the form. If it does, then you'll have to run the waiting form on a different thread. Something like
private void Frm_Land_Load(object sender, EventArgs e)
{
Thread th = new Thread(gu.Show_WaitingForm);
th.Start();
this.Initialize_Data();
gu.Hide_WaitingForm();
}
class GU
{
Form f;
void Show_WaitingForm()
{
f = new Form();
f.ShowDialog();
}
void Hide_WaitingForm()
{
if (this.InvokeRequired)
{
f.BeginInvoke(new MethodInvoker(Hide_WaitingForm), null);
}
else
{
f.Close();
}
}
}
Hope this helps.
|
|
|
|
|
Dear All,
I am clueless about how to create more graphically rich menus such as the ones that are used in Microsoft Office Application.
Thank you!
M. Nauman Yousuf
"Mess with the Best, Die like the rest"
|
|
|
|
|
Google around. You should actually do a search here at CP and I think there are a few graphically rich controls...Sorry, too lazy to search for you
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
if you want to design graphically rich menus like offce 2007, you are better buying a third party control instead of designing it that's just my opinion. Look up www.divelements.co.uk if you want office 2007 style menus.
|
|
|
|
|
Hello,
I have created a setup project and added some dialog boxes to the user interface.
I have added the dialog with 4 text boxes. Then using Orca I have modified this and added a radio button group with 2 radio buttons (A and B).
What I am trying to do is when the user selects A then all text boxes will be enabled. And when the user selects B then only 2 text boxes will be enabled.
This is my first time in using Orca, and anyone explain how to add this condition for selecting the radio buttons.
Many thanks advance,
Steve
|
|
|
|
|
Hello,
I load dynamically an external class library compiled as a .dll file, using this kind of code:
Assembly classLibrary1 = null;
using (FileStream fs = File.Open(path, FileMode.Open))
{
using (MemoryStream ms = new MemoryStream())
{
//... (Read file byte per byte and store it to memorystream)
classLibrary1 = Assembly.Load(ms.ToArray());
}
}
foreach (Type type in classLibrary1.GetExportedTypes())
{
if (type.GetInterface("IPClass") != null)
return Activator.CreateInstance(type) as IPClass;
}
I would like these objects (created from an external assembly) to have access to a single instance of an object I previously created (in the project that loads external classes).
For example:
The static class 'Hello' in my main project has to be accessed by the loaded classes. But only to the 'Hello' instance of the main projet (what I can't apparently do when using class from external assemblies)
Somebody knows how to deal with this issue?
Thank you,
Thomas
|
|
|
|
|
thg971 wrote: The static class 'Hello' in my main project has to be accessed by the loaded classes. But only to the 'Hello' instance of the main projet (what I can't apparently do when using class from external assemblies)
Why doesn't it work? AFAIK, singletons remain single within an AppDomain, so as long as the external assemblies are also loaded in the same AppDomain as your Hello class, they should be accessing the same instance.
If not, then you would have to derive your singleton from MarshalByRef and modify the code in the external assemblies to explicitly accept an instance of your singleton (as a property setter, for example) and then use that instance.
|
|
|
|
|
how can i get index of specified item in multidimension array ?
|
|
|
|
|
By using nested for loops to step through and checking for when the element is equal to your value.
valueSearch = "Value to search for";
for (int x = 0; x < array.GetLength(0); x++)
{
for (int y = 0; y < array.GetLength(1); y++)
{
for (int z = 0; z < array.GetLength(2); z++)
{
if (array[x][y][z] == valueSearch)
{
}
}
}
}
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
I would say that if you need to be searching, arrays aren't the way to go.
But if you must use arrays, the only tip I would add to the above is a break statement jump out of the nested for loops when you actually find the value (no need in running through the rest of the items).
J
Make the logo bigger
|
|
|
|
|
True that
There are 10 types of people in the world, those who understand binary and those who dont.
|
|
|
|
|
Hi im new to Both C# and sql and exept from that my problem is:
I´ve managed to connect to a mssql database (express edition) from my C# program and I have the sqldata reader to read my question to listboxes in my windowsForm. Ive understood from "Beginners guide to accessing SQL Server through C#" that once you got your connection running and the reader has read the table in the database You can rephrase your question without reading directly to the database.
If that is correct, Is it possible to establish a connection to the sql database in "program.cs" and get your reader to read the whole table and then let different windowsForms make sql questions to that reader? Im hoping to gain less questions to the DB and its supposed to get the table every five minutes or something.
I would be very happy if anyone could help me in this matter
Here is an example of code in my Form:
public partial class BinMonitor : Form<br />
{<br />
private SqlConnection conn;<br />
private SqlCommand cmd;<br />
private SqlDataReader reader;<br />
string Sql;<br />
<br />
public BinMonitor()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
private void timer1_Tick(object sender, EventArgs e)<br />
{<br />
textBox1.Text = DateTime.Now.ToLongTimeString();<br />
<br />
}<br />
private void timer2_Tick(object sender, EventArgs e)<br />
{<br />
<br />
listBox1.Items.Clear();<br />
listBox2.Items.Clear();<br />
listBox3.Items.Clear();<br />
string connStr = "server=DBserver; user id=user; password=pwd; database=flights;Trusted_Connection=yes;";<br />
SqlConnection conn = new SqlConnection(connStr);<br />
conn.Open();<br />
reader = null;<br />
cmd = new SqlCommand("SELECT * FROM BinMonitor Where Departure !<" + "'" + textBox1.Text + "'" + "order by Departure ASC", conn);<br />
reader = cmd.ExecuteReader();<br />
reader.Read();<br />
<br />
while (reader.Read())<br />
{<br />
listBox1.Items.Add(reader.GetString(0));<br />
listBox2.Items.Add(reader.GetString(1));<br />
listBox3.Items.Add(reader.GetString(2));<br />
}<br />
}<br />
<br />
<br />
<br />
}<br />
}
Lost in space
|
|
|
|
|
I am very happy to help you, I would not know that you want to express the link MYSQL or other intention.
I hope you can more simple expression of what you mean.
MSN : chenqi1000y@163.com
|
|
|
|
|
Thank you for helping!
I was hoping to get an answer if its possible to make the sqlreader work for several Forms at the same time, and if so how?
|
|
|
|
|
erikhjerpe wrote: If that is correct, Is it possible to establish a connection to the sql database in "program.cs" and get your reader to read the whole table and then let different windowsForms make sql questions to that reader?
No. A reader is a one-time-forward-only view of the data that is being retrieved from the database. Once a row has been read from the reader you cannot go back and read it again.
You may wish to look into DataAdapters in order to Fill a DataSet with the data which you can store in a central location and allow the forms to access.
erikhjerpe wrote: Here is an example of code in my Form
It is unwise to access data dirctly from a form.
erikhjerpe wrote: cmd = new SqlCommand("SELECT * FROM BinMonitor Where Departure !<" + "'" + textBox1.Text + "'" + "order by Departure ASC", conn);
reader
This code is susceptable to SQL Injection Attacks. Please read up on SQL Injection Attacks and Tips on How to Prevent Them[^]
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Thank you very much for the tips, I certainly will look into DataAdapters, have a vague ideea that thats what I´m looking for. About Injection attacks Im´not afraid since the application is supposed for a closed network and without any input from users other than to load a form. (Trying to build a system of info displays).
Anyway thanks a lot for your answers
|
|
|
|
|
erikhjerpe wrote: About Injection attacks Im´not afraid since the application is supposed for a closed network and without any input from users other than to load a form
Statistically most system breaches are inside jobs.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
You´re right, at the moment I´m taking my first trembling steps in programming, and it´s probably a good Idea to learn from the start to think about security.
Thanks
|
|
|
|
|
We all have to start somewhere. Just a few tips of my own and I apologize if any are repeats.
Think stored procedures. That will solve the Sql injection attack problem by itself. At the very least use parameterized queries. This will solve more than just security issues. Imagine the headache of having to debug your app at 2am because somebody entered "Bob O'Malley" into a textbox?
put data connections, data readers, and commands into using statements. Especially the connections. Again, you don't want to be figuring out why your server came to a screeching halt at 2am because no connections ever closed.
DataSets are great, you can also use the reader to load that data into a collection of objects, close your connections, then pass the collection around anywhere you need it.
I know some of this may seem advanced if you're just getting started, but remember this is where you want to be going. It's never to early to start doing it right.
Oh, one more thing that I just noticed: you don't need a priming read on your datareader. This will actually cause you to throw away the first row of data. HTH.
J
Make the logo bigger
|
|
|
|
|
Dear all,
I am facing a problem with a javascript function i had with me javascript for country generation and also on change of country state generation w.r.t of country but i want to fetch the selected value of country and state and to update in the database using sqlserver.
sai krishna
|
|
|
|
|
If you divide your text into sentences, it might be possible to understand what you are trying to say.
As I gather it, you want to do something (update? insert?) with an MS SQL Server database from Javascript?
You can't do that. Well, it's possible, but that would mean that you expose your database login to everyone.
You have to post the information to the server, where you do the database work.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks guffa,
for ur prompt msg, but i have a javascript code written for country selection and this is the aspx statement i am writing to call javascript
but in the javascript onchange event is to give the corresponding state of the country another javascript so what i have to do to get the selected value of the country
thanks once again
sai krishna
|
|
|
|
|
I'm not entirely sure I understand your problem either, but what it sounds like you want to do is populate a state combo box based on the users selection in a country combo box. You don't want connection strings in your web page unless your resume is up to date. I think you're going to have to look into an ajax solution unless you want to do a full postback each time the user changes their selection.
J
Make the logo bigger
|
|
|
|
|
dsaikrishna wrote: I am facing a problem with a javascript function i had with me javascript for country generation and also on change of country state generation w.r.t of country but i want to fetch the selected value of country and state and to update in the database using sqlserver.
Okay.
#1. Declare one variable in code-behind to hold the status.
string selectedCountry = string.Empty;
#2. Add one server-side hidden field (a HTML hidden field with RunAt="Server") in your page.
<input id="Hidden1" type="hidden" runat="server" onserverchange="Hidden1_ServerChange"/><br />
#3. Add change event of this hidden field
<br />
protected void Hidden1_ServerChange(object sender, EventArgs e)<br />
{<br />
<br />
}
#4. In onchange event of Country list, you can set the value to this hidden field.. For example, if you select "Singapore" from combobox, set this to hidden field by using javascript.
var objHdf = document.getElementById('Hidden1');<br />
objHdf.value = document.getElementById('cboCountry').selectedtext;<br />
#5. As soon as the value of hidden field get changed, the server side event of hidden field will be invoked. So, get the value from hidden and set it to string that we declare earlier..
<br />
protected void Hidden1_ServerChange(object sender, EventArgs e)<br />
{<br />
selectedCountry = Hidden1.Value; <br />
}
Okay. now, you get the value so, you can insert it to SQL database..
Hope it helps..
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
i would like to know how to create and use crystal reports in c#.net . do any one can briefly explain this.
|
|
|
|