c#-2.0

Using C# MethodInvoker.Invoke() for a GUI app… is this good?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 08:32:49
问题 Using C# 2.0 and the MethodInvoker delegate, I have a GUI application receiving some event from either the GUI thread or from a worker thread. I use the following pattern for handling the event in the form: private void SomeEventHandler(object sender, EventArgs e) { MethodInvoker method = delegate { uiSomeTextBox.Text = "some text"; }; if (InvokeRequired) BeginInvoke(method); else method.Invoke(); } By using this pattern I do not duplicate the actual UI code but what I'm not sure about is if

Embedding a DOS console in a windows form

那年仲夏 提交于 2019-12-17 04:59:11
问题 Is it possible to embed a DOS console in a Windows Form or User Control in C# 2.0? We have a legacy DOS product that my Windows app has to interact with, and it's been requested that an instance of the legacy product should run within the Windows application. At the moment, I'm using the user32.dll to locate the window that the DOS product is running in, minimising then maximising the window, and typing characters into the window. This isn't a very good solution to the problem, as it means my

Embedding a DOS console in a windows form

泪湿孤枕 提交于 2019-12-17 04:58:33
问题 Is it possible to embed a DOS console in a Windows Form or User Control in C# 2.0? We have a legacy DOS product that my Windows app has to interact with, and it's been requested that an instance of the legacy product should run within the Windows application. At the moment, I'm using the user32.dll to locate the window that the DOS product is running in, minimising then maximising the window, and typing characters into the window. This isn't a very good solution to the problem, as it means my

How to statically link libraries for a C# ClassLibrary?

拟墨画扇 提交于 2019-12-13 13:02:10
问题 I am creating a Class LLibrary in c# by using microsoft provided Dll's. Now i want to statically add those Microsoft provided libraries to My Dll.How can i do this. I have simply added a reference to those Microsoft provided Dlls and creating My Dll? Is it fine or not? if Microsoft provided dll is not available on other machine then my Dll may fails i need to add the libraries statically?? How can i do this?? 回答1: There's no such thing as statically linking to another assembly in .NET. There

Embedded statement error [duplicate]

一曲冷凌霜 提交于 2019-12-13 10:14:57
问题 This question already has answers here : Variable declarations following if statements (4 answers) Closed 6 years ago . I have a simple custom list class and I am trying to implement IComparable to it, but it's not working to be honest. I tried MSDN and other blogs and still same. public class sortDateTime : IComparable { protected DateTime m_startDate, m_endDate; public DateTime startDate { get { return m_startDate; } set { m_startDate = startDate; } } public DateTime endDate { get { return

Generate random words

橙三吉。 提交于 2019-12-13 10:13:14
问题 apple, mango, papaya, banana, guava, pineapple - How to generate these words randomly (one by one) using c# ? Please help me to generate the words randomly from the list of words I have.. 回答1: Random rnd = new Random(); string GetRandomFruit() { string[] fruits = new string[] { "apple", "mango", "papaya", "banana", "guava", "pineapple" }; return fruits[rnd.Next(0,fruits.Length)]; } 回答2: You can get "random sorting" with LINQ's OrderBy method and using Guid s var words = new [] {"apple",

Programmatically how to create task scheduler in windows server 2008

£可爱£侵袭症+ 提交于 2019-12-13 07:05:16
问题 The task scheduler which works fine when running my application in Windows Xp because task file is saved as .job. But in windows server 2008 the task scheduler file is saving in XML format. How to get the Task scheduler in Xml format? 回答1: Have a look at Task Scheduler API http://msdn.microsoft.com/en-us/library/aa383614(v=vs.85).aspx or use Schtasks.exe http://msdn.microsoft.com/en-us/library/bb736357.aspx 来源: https://stackoverflow.com/questions/5218482/programmatically-how-to-create-task

How to create sets of the serialized objects C#

…衆ロ難τιáo~ 提交于 2019-12-13 03:51:42
问题 There are various types, in a special case which can be configured in different ways. How to serialize them? [Serializable] [XmlRoot("RootXml", Namespace = "")] public class RootXml { object _schemaVersion; [XmlElement("SchemaVersion")] public object SchemaVersion { get { return _schemaVersion; } set { _schemaVersion = value; } } List<object> _test; [XmlElement("Test")] public List<object> Test { get { return _test; } set { _test = value; } } public RootXml() { } } I.e. root can include

Save list of Arabic strings in database

我怕爱的太早我们不能终老 提交于 2019-12-13 03:19:21
问题 I have a c# program. I have list of string. The elements of that list in Arabic. When I try to save the elements of list in database I see symbols "??????" Here my code List<string> _names = new List<string>() { "ذهب", "قال", "تعال", "متى", "البرمجة", "احمد" }; SqlConnection connection = new SqlConnection("Server=DESKTOP-JRS3DQ4; DataBase=Library_DB; Integrated Security=true"); connection.Open(); for (int index = 0; index < _names.Count; index++) { SqlCommand command = new SqlCommand("INSERT

Random minutes in C# 2.0

浪尽此生 提交于 2019-12-13 01:17:12
问题 Ho do I go about adding random minutes to column in dataset, here is my code: protected void btnUpdateTable_Click(object sender, EventArgs e) { foreach (DataRow dr in ds.Tables[0].Rows) { ///check if column[logout] is null or empty, fill it if(dr.IsNull("logout_time")) { ///get the login colum datetime /// add random datetime to it if (!dr.IsNull("login_time")) { DateTime dt = Convert.ToDateTime(dr["login_time"]); dt = dt.AddMinutes(?);/// "?"<--here I want to add random minutes } } } Any