|
Let me try to explain the my problem with my bad english...
I have an aplication that runs a process in background and i was forced to stop the execution of the aplication until this process is complete, but this process could long for large seconds. So i must have a way to warn the user to wait, i thougt in a messageBox , and i do it, but than this messageBox stays until the user clicks ok, not until the end of the process.
I have tried with a form but it does not work to well. The form stays full of holes (the places where it should load the labels).
Could you sugest me other solution or a way to solve the problem with the form?
thanks for your help.
PC
|
|
|
|
|
So you're using two seperate threads. Using the other thread (not the background one) create a timer that will tick after say a minute. When it ticks check to see if the background thread is still running. If it's still running show the messagebox. Even when the box is open the other thread will still run.
|
|
|
|
|
Yes, you are rigth i'm following your advice, but it still not perfect because if the thread that runs in background ends, and the user dont press OK before, i will have the messageBox in the screen but the program its already in another fase (since its a caind of Wizard).
But i think i must live with that because i don´t find a better answer.
Perhaps i should follow your 1st advice and built my one class for the messageBox.
Thanks for the help
PC
|
|
|
|
|
|
thanks for the tip, that code seems very helpfull and its a better solution that the messageBox.
Many thanks
PC
|
|
|
|
|
One way is to create your own form with an OnTimer event. The form can be just a label that you assign text to prior to showing it. Then the OnTimer event can call this.close();
|
|
|
|
|
I have already solved that problem, just like you sugest...
Thank you
PC
|
|
|
|
|
Had a lot of trouble finding an easy way to accomplish this; thought I would pass this code on.
I wrote a program called SatAmp that has a WebControl http page it sends out for external control of the application, and I wanted a way to help people find their external IP Address from the program itself without requiring them to actually visit a website for the purpose.
Here is my solution:
<br />
using System;<br />
using System.IO;<br />
using System.Net;<br />
using System.Text;<br />
<br />
namespace SatAmp.Utility_Classes<br />
{<br />
class IPRequest<br />
{<br />
public static string GetIP()<br />
{<br />
StringBuilder sb = new StringBuilder();<br />
<br />
byte[] buf = new byte[8192];<br />
<br />
HttpWebRequest request = (HttpWebRequest)<br />
WebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");<br />
<br />
HttpWebResponse response = (HttpWebResponse)<br />
request.GetResponse();<br />
<br />
Stream resStream = response.GetResponseStream();<br />
<br />
string tempString = null;<br />
int count = 0;<br />
<br />
do<br />
{<br />
count = resStream.Read(buf, 0, buf.Length);<br />
<br />
if (count != 0)<br />
{<br />
tempString = Encoding.ASCII.GetString(buf, 0, count);<br />
<br />
sb.Append(tempString);<br />
}<br />
}<br />
while (count > 0);
<br />
<br />
return sb.ToString();<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
public void buttonGetMyIP_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
string ip = IPRequest.GetIP();<br />
<br />
this.labelMyIpAddress = ip;<br />
}<br />
catch<br />
{<br />
this.labelMyIpAddress = 000.000.000.000;<br />
}<br />
}<br />
|
|
|
|
|
How can i find a child object location within it's parent container. Thanks
|
|
|
|
|
netJP12L wrote: How can i find a child object location within it's parent container
I think you're going to need to elaborate a little bit.
Are you talking about the location of a control on a form? The location of a control within another control? The the index of an item in an array, List<>, or other collection?
|
|
|
|
|
Does the parent container have a find method ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You're as bad as my partner's children..... try looking for it!
|
|
|
|
|
Hello
I'm already doing different updates in different tables using MySqlCommandbuilder and I don't have particular problems
BUT
For one dataset resulting of a query with joins, and needing only to uptate one column in one table the commandbuilder can't work
So I decide to build my own command as below
Unfortunately, it does not work too : everything seems ok, the update is returning a count but nothing change in the DB
So I decided to do everything manualy in a loop (second example) : It works.
But I'm still trying to understand why the first option is not working ?
Using a "manual" loop
MySqlCommand cmd;<br />
string xCmd;<br />
DataTable dtr = dsRit.Tables[0];<br />
<br />
for (int i = 0; i < dtr.Rows.Count; i++)<br />
{<br />
DataRow dr=dtr.Rows[i];<br />
xCmd = "UPDATE tours SET order1=" + dr["order1"].ToString() + " WHERE id=" + dr["id"].ToString();<br />
cmd=new MySqlCommand(xCmd, MyConn.conn);<br />
int nUpd = cmd.ExecuteNonQuery();<br />
}
|
|
|
|
|
Hi All,
I posted about this a couple of days ago and I'm still trying to solve the problem. I just can't see what is different between my two uses of the same serialization class I've written (DataBaseStorage), one works the other doesn't.
I have a custom ObservableCollection defined that is marked as [Serializable] and implements all the required things (it works!):
[Serializable()]
public class FileInformation : ISerializable
{<snipped>
FileInformation also contains:
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{<snipped>
I've hard coded a save into a class that builds a list of local files and this use of my serialization class works without any problems. In this class I create a new instance of my FileInformation collection using:
ObservableCollection<FileInformation> Database = new ObservableCollection<FileInformation>();
This class then goes off and does its thing to populate that collection then as I said above I have hard coded this save operation before returning the collection to my main window:
DataBaseStorage savedata = new DataBaseStorage();
savedata.SaveDatabaseData(@"App_Data\TestSaveLatest.dat", Database);
return Database;
The returned collection is then bound to a xamDataGrid (a WPF datagrid made by Infragistics). I can also start my app in debug mode and load this hard coded saved file back into the interface using my deserialize method in DataBaseStorage. The exception on the serialize method only happens when I try to save via the interface. The code there looks like:
if (fd.DialogResult == true)
{
string fileToSaveToo = fd.cmbFilePicker.Text;
DataBaseStorage savedata = new DataBaseStorage();
savedata.SaveDatabaseData(fileToSaveToo, database);
SampleSortMainScreen.Opacity = 1.0;
}
This is a bit of code from a button click bound to the interface using CommandBindings. When it hits the serialize line here:
public void SaveDatabaseData(string filename, ObservableCollection<fileinformation> objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}</fileinformation>
I get the exception:
Type 'System.Collections.Specialized.CollectionChangedEventManager' in Assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
I'm not entirely sure what this exception is telling me to be honest, I've googled it read as much as I can find about object serialization and the pitfalls that come from serializing events (there aren't any events tied to my FileInformation class. My dev has ground to a halt at the moment. I'm new to C# and .NET and this has me completely stumped. Am I doing something really daft like trying to serialize the WindowsBase assembly?
Thanks for any help folks, I'm now going slowly mad and round and round in circles looking for info on the web.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
|
Hi Chrisko,
Thanks for the reply. If I read that correctly (I'm going to have to read up on what Type constraints are as I've never heard of them) that is saying that I should add in this constraint code:
[Serializable]<br />
class MySerializableClass<t><br />
{<br />
T m_T;<br />
<br />
static MySerializableClass() <br />
{<br />
ConstrainType(typeof(T));<br />
}<br />
static void ConstrainType(Type type)<br />
{<br />
bool serializable = type.IsSerializable;<br />
if(serializable == false)<br />
{<br />
string message = "The type " + type + " is not serializable";<br />
throw new InvalidOperationException(message);<br />
}<br />
}<br />
}</t>
And then test my object. If the test fails I need to totally rethink my object? I still don't get why it works one way and creates a re-loadable file but I can't do it from another location in my app ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
The well known pair BeginReceiveFrom(),EndReceiveFrom() doesn't seem to work well
if multiple UDP clients from different addresses and/or ports are sending UDP datagrams to
the same socket where a server is listening: the server application accepts only datagrams from
the socket (address + port) which first sent to the receiving socket, all the rest is discarded.
Any suggestion or workaround?
|
|
|
|
|
Have you solved this?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi,
I am experimenting a bit with fluent interfaces and decided to try to build a fluent interface to describe a screen layout. I started with an idea of how I wanted the interfaces to work together and mainly focused on intellisense:
<br />
screen.SplitVertical()<br />
.Left.SplitHorizontal()<br />
.Top.CreateRegion("region1")<br />
.Bottom.CreateRegion("region2")<br />
.Right.CreateRegion("main")<br />
.Done();<br />
I wanted to be able to split the screen into two areas (Left/Right, or Top/Bottom) and then define a named region for that area. Or, I should be able to indefinitely split and area into sub-areas. Furthermore, I wanted to guarantee that once a screen was split, both areas had to be defined into a region -- and I wanted intellisense to help me out on that.
So, I built a set of interfaces to make this happen (not worrying about implementation yet). As I was doing this, I ran into an issue that goes a bit beyond my understanding of generics.
First, I thought to compose a bunch of interfaces that contained verbs, or actions, that can be performed. Each interface had a generic parameter that determined the return type of the verb:
<br />
public interface ITop<X> { X Top { get; } }<br />
public interface IBottom<X> { X Bottom { get; } }<br />
public interface ILeft<X> { X Left { get; } }<br />
public interface IRight<X> { X Right { get; } }<br />
public interface ICreateRegion<X> { X CreateRegion(); }<br />
public interface ISplitVertical<X> { X SplitVertical(); }<br />
public interface ISplitHorizontal<X> { X SplitHorizontal(); }<br />
public interface IDone { void Done(); }<br />
Then, I defined a interface to join multiple interfaces together at each branch in the fluent interface:
<br />
public interface IBranch1<X> :<br />
ICreateRegion<X>,<br />
ISplitHorizontal<IBranch2<X>>,<br />
ISplitVertical<IBranch3<x>> { }<br />
<br />
public interface IBranch2<X> :<br />
ITop<IBranch1<IBottom<IBranch1<X>>>>, <br />
IBottom<IBranch1<ITop<IBranch1<X>>>> { }<br />
<br />
public interface IBranch3<x> :<br />
ILeft<IBranch1<IRight<IBranch1<X>>>>, <br />
IRight<IBranch1<ILeft<IBranch1<X>>>> { }<br />
</x>
Knowing that this was really ugly code, I decide to build a quick test:
<br />
public static class Foo<br />
{<br />
public static T FluentFactory<T><br />
{<br />
throw new NotImplementedException("Not yet implemented");<br />
}<br />
<br />
public static void Bar()<br />
{<br />
IBranch1<IDone> screen = FluentFactory<IBranch1<IDone>>();<br />
<br />
screen.Create().Done();<br />
<br />
screen.SplitHorizontal()<br />
.Top.Create()<br />
.Bottom.Create()<br />
.Done();<br />
<br />
screen.SplitVertical()<br />
.Left.Create()<br />
.Right.Create()<br />
.Done();<br />
<br />
screen.SplitVertical()<br />
.Left.SplitHorizontal()<br />
.Top.Create()<br />
.Bottom.Create()<br />
.Right.Create()<br />
.Done();<br />
}<br />
}<br />
<br />
static class Program<br />
{<br />
public delegate void Func();<br />
<br />
private static void TryAndCatch(Func x)<br />
{<br />
try<br />
{<br />
x.Invoke();<br />
}<br />
catch (NotImplementedException e)<br />
{<br />
MessageBox.Show(e.Message);<br />
}<br />
catch (TypeLoadException e)<br />
{<br />
MessageBox.Show(e.Message);<br />
}<br />
}<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
TryAndCatch(Foo.Bar);<br />
}<br />
And, sure enough, I got a TypeLoadException saying that I was using my generics recursively.
I changed the way the interfaces worked a bit, and arrived at this:
<br />
<br />
public interface ITop<X> { X Top { get; } }<br />
public interface IBottom<X> { X Bottom { get; } }<br />
public interface ILeft<X> { X Left { get; } }<br />
public interface IRight<X> { X Right { get; } }<br />
public interface ICreateRegion<X> { X CreateRegion(); }<br />
public interface ISplitVertical<X> { X SplitVertical(); }<br />
public interface ISplitHorizontal<X> { X SplitHorizontal(); }<br />
public interface IDone { void Done(); }<br />
<br />
public interface IBranch1<X> :<br />
ICreateRegion<X>,<br />
ISplitHorizontal<IBranch2<X>>,<br />
ISplitVertical<IBranch3<x>> { }<br />
<br />
public interface IBranch2<X><br />
{<br />
IBranch1<IBottom<IBranch1<X>>> Top { get; }<br />
IBranch1<ITop<IBranch1<X>>> Bottom { get; }<br />
}<br />
<br />
public interface IBranch3<x><br />
{<br />
IBranch1<IRight<IBranch1<X>>> Left { get; }<br />
IBranch1<ILeft<IBranch1<X>>> Right { get; }<br />
}<br />
</x>
Now, the TypeLoadException goes away and I simply get my (expected) NotImplemented exception.
My question is -- what is different about the first and second approach?
modified on Thursday, March 20, 2008 2:23 PM
|
|
|
|
|
I have a class declared as below.
<br />
class Error_codes<br />
{<br />
public string[] Error_category;<br />
public int[] Error_value;<br />
public string[] Error_comments;<br />
}<br />
I tried instantiating objects to the class by using the constructor as follows
<br />
Error_codes[] error_details = new Error_codes[70];<br />
<br />
TextReader sr = File.OpenText(ErrorCodes_FILE_NAME);<br />
{<br />
string input=null;<br />
int i = 0;<br />
while ((input=sr.ReadLine())!=null) <br />
{<br />
Regex regEx = new Regex("#(\\w*)");<br />
string[] tokens = regEx.Split(input);<br />
error_details[i]= tokens[2].ToString();<br />
error_details[i] = 20;
error_details[i] = tokens[4].ToString();<br />
i++;<br />
}<br />
sr.Close();<br />
}<br />
But I see an error "Cannot implicitly convert type 'string' to 'LoggingImprovements.Error_codes'". How do we instantiate constructors with errors?
|
|
|
|
|
error_details[i] is an object of type Error_codes
so when you use error_details[i]= tokens[2].ToString(); you are indeed trying to assign a string to and object of type Error_codes, i assume this lives in the LoggingImprovements namespace.
are you trying to do this?
error_details[i].Error_category = tokens[2].ToString();
in which case you would want your error_codes class to look like this:
class Error_codes<br />
{<br />
public string Error_category;<br />
public int Error_value;<br />
public string Error_comments;<br />
}
Hope this helps
|
|
|
|
|
Thanks Russel. I understood my error.
|
|
|
|
|
Hello friends
can anyone let me know how to send email through C#
if possible do let me knowplz
|
|
|
|
|
|
And don't cross post.
led mike
|
|
|
|