Yes, because you must use the window handle of the Application:
theprocess.MainWindowHandle
use that one...
Yes, because you must use the window handle of the Application:
theprocess.MainWindowHandle
use that one...
Here:
RegistryKey subKeys = HKCU.OpenSubKey("Software\\VB and VBA Program Settings\\Company\\", true);
The problem is the way you declare the out of class timer. The way it is defined, means it will run in its own thread.
What?:D That timer is certainly NOT out of class.
Threads can not adjust non-thread safe components in other threads (like this main thread).
That's completely wrong. What do you think methods like Control.BeginInvoke() are there for? It's absolutely possible to use UI controls in a non-UI thread.
private System.Timers.Timer timerClock = new System.Timers.Timer();
Above is the line that is causing your error.
Comment out that line, drag a timer component onto the form, and re-wire it to use the onTick event instead of the onTimer event (different args).
Wrong again. That line has absolutely nothing to do with the problem he's facing.
NB: timerClock could be marked as read-only, but ok, that's just a matter of personal taste.
Otherwise please mark this post as solved.
Well, what about marking it as solved now?:P Altough that code could be done in a much shorter way using the methods of eg. the datetime class
Here's the corrected version (only relevant code is posted):
private delegate void SetTextBoxTextHandler(string text);
private void SetTextBoxt(string text)
{
textBox1.Text = text;
}
public void OnTimer(object sender, ElapsedEventArgs e)
{
try
{
clockTime++;
int countdown = alarmTime - clockTime;
if (alarmTime != 0)
{
string formattedTime = secondsToTime(countdown);
if (textBox1.InvokeRequired)
{
textBox1.BeginInvoke(new SetTextBoxTextHandler(SetTextBoxt), new object[]{formattedTime});
}
else textBox1.Text = formattedTime;
}
if (clockTime == alarmTime)
{ …
Try to correct that one by yourself, the answer is right there in the code, have a look at how i handle the other case (it's exactly the same), we're not here to chew you every piece in advance...
Here is corrected source:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace LanChat
{
public class LanChat : Form
{
public Button buttonAdvertise;
public Button buttonSend;
public Button buttonStop;
public ComboBox comboBoxUserNames;
public IContainer components;
public ContextMenu contextMenuNotify;
private bool IsThreadRunning = false;
public Label label1;
public MenuItem menuItem3;
public MenuItem menuItemAbout;
public MenuItem menuItemExit;
public MenuItem menuItemOpen;
public NotifyIcon notifyIcon;
public PictureBox pictureBox1;
public RichTextBox richTextBoxRecieveMsg;
public RichTextBox richTextBoxSendMsg;
private ReaderWriterLock rwl = new ReaderWriterLock();
private Thread thread;
private ArrayList userList = new ArrayList();
public LanChat()
{
InitializeComponent();
thread = new Thread(new ThreadStart(MulticastListener));
thread.Start();
String message = "Hello$" + GetUserName();
MulticastSend("224.168.100.2", 1000, message);
notifyIcon.Icon = LoadIcon();
Icon = LoadIcon();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
[STAThread]
private static void Main()
{
LanChat f = new LanChat();
Application.Run(f);
}
public void buttonSend_Click(object sender, EventArgs e)
{
if (richTextBoxSendMsg.Text == "")
return;
String message = "MSG:$" + GetUserName() + " : " + richTextBoxSendMsg.Text;
string[] host = comboBoxUserNames.Text.Split('\\');
if (host.Length > 1)
{
string hostName = Dns.GetHostByName(host[0]).AddressList[0].ToString();
MulticastSend(hostName, 1000, message);
richTextBoxSendMsg.Text = "";
}
}
public void buttonAdvertise_Click(object sender, EventArgs e)
{
String message = "Hello$" + GetUserName();
MulticastSend("224.168.100.2", 1000, message);
}
public void buttonStop_Click(object sender, EventArgs e)
{
String message = "Stop$" + GetUserName();
MulticastSend("224.168.100.2", 1000, message);
}
public void Form1_Closing(object sender, CancelEventArgs e)
{
rwl.AcquireWriterLock(10);
IsThreadRunning = false;
rwl.ReleaseWriterLock(); …
There are overloads for that method,
have a look here : http://msdn2.microsoft.com/en-us/library/wcxyzt4d.aspx
should be the one you need
That is of course only in case FieldName is of type string
The short-circuit is working right, however your code is not, a short-circuit evaluation should be written like this :
if ((cr.FieldName == null) || (cr.FieldName.Length == 0))
throw new Exception("Null FieldName in SQLNumStrategy");
Note the 2 pipes (which represent a conditional-OR)
The framework proposes also a convenience method for your particular case which is string.IsNullOrEmpty():
http://msdn2.microsoft.com/en-us/library/system.string.isnullorempty.aspx
From what I can tell, C# doesn't do that, at least by default. Is there a compiler directive or attribute which will allow that?
So basically you think c# doesn't support short-circuit evaluation ?
Have a look here: http://msdn2.microsoft.com/en-us/library/2a723cdk(VS.71).aspx
@iamthwee: Those kind of answers are not very helpful, altough they might amuse you (weird sense of humour). In case you intend to post such a crap again in the future, why don't you think twice about it and (possibly) keep out of the discussion?
Try this: string[] lines = Regex.Split(s, "(.+?)(\\*{0,13}RECIVED MAIL)\\s*(PQR.+)(New PQR.+)(Respond.+)");
Just for the gallery, see first part of code in my previous post:
string format = "MM.dd.yyyy HH:mm:ss";
lines.Sort(new Comparison<string>(delegate(string a, string b)
{
string dateA = Regex.Match(a, "\\[(.+)\\]").Groups[1].Value;
string dateB = Regex.Match(b, "\\[(.+)\\]").Groups[1].Value;
return (DateTime.Compare(DateTime.ParseExact(dateA, format, null),
DateTime.ParseExact(dateB, format, null)));
}));
When you catch the exception you should output its message, and not "blabla..is not a valid image file". That way you'll be able to identify what's going wrong.
This is usually done with recursion:
void Fetch (string SourceString)
{
arrayCount = 0;
DirectoryInfo di = new DirectoryInfo(SourceString);
FileInfo[] rgFiles = di.GetFiles("*.mp3");
foreach (FileInfo fi in rgFiles)
{
fileIndex[arrayCount] = fi.FullName;
MessageBox.Show(fileIndex[arrayCount]); // Temp for testing
arrayCount++;
}
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo diNext in dirs)
{
Fetch(diNext.FullName); // HERE!
}
}
Note: that code is non-buildable of course, i just put your code in a method to show you the way to go.
Hi, if every line starts with the date, this should do the trick:
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\data.txt", FileMode.Open)))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
lines.Sort();
What i don't understand in your code is that you first format the DateTime to a string and then you construct another DateTime object from that same string; is that step absolutely necessary? By reading that small snippet you posted I can't see any obvious reason why one should do that, imo this adds overhead and confusion to the code.
If you need to do some conversion from local time to utc time or vice versa, have a look at DateTime.ToLocalTime or DateTime.ToUniversalTime methods
You can do something like this:
if (st.ToLower().Contains(data.ToLower()))
It's possible that your custom RandomNumberGen class is not seeded properly, where is the seed set?
This is because you instantiate the stringbuilder object via
strbuild = new StringBuilder();
in the loop, you have to instantiate it outside when you first declare it
StreamReader reader = new StreamReader(@"d:\web_extract.txt",Encoding.Default);
StringBuilder strbuild = new StringBuilder(); <--here
Error 1 The best overloaded method match for 'string.ToString(System.IFormatProvider)' has some invalid arguments
This is because you call ToString on type string instead of long.
Make sure your code looks like this:
long num = 4445556666;
string s = num.ToString("(###)-###-####");
I would do this via regex, here's some example:
static void Main(string[] args)
{
const string theRegexString = "quote\\.jsp\\?symbol=([^=>]+)\\s*>";
Regex regex = new Regex(theRegexString, RegexOptions.Compiled);
using (StreamReader inFile = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.txt"))
{
string contents = inFile.ReadToEnd();
MatchCollection matches = regex.Matches(contents);
foreach (Match match in matches)
{
Console.WriteLine(match.Groups[1]);
}
}
Console.ReadKey();
}
Console.Read();
It's waiting for the user to press the ENTER key here, so it stops
Ok, i think it should be quicker now, i introduced some cryptor class with own progressbarupdatehandler. There's still some work for you to do though, mainly the way how you get the filepaths from the open/save dialogs.
It would help us if you would paste use the complete source code, otherwise it's hard to recreate your problem (and eventually help you).
I don't see where you actually declared your delegate ?
somewhere in the namespace put this:
public delegate void ProcessingCompleteDelegate();
also to fire an event you usually do it like this:
if (SearchComplete != null) SearchComplete()
that code would go in your Start() method
What about having a look at Convert.ToBase64String and Convert.FromBase64String ?
Yes, and to populate the int array of the Arrays class you could either pass an int array in the ctor of the Arrays class or expose a setter via the MyArray property.
Hi, i don't know exactly what you want to do there, but if you want only to make your int array public by a property you could do this in your class:
public int[] MyArray
{
get
{
return myArray;
}
}
Then when you want to call it:
Arrays a = new Arrays();
foreach (int i in a.MyArray)
{
MessageBox.Show(this, i.ToString());
}
try this solution:
bool SortBylength(const string& a, const string& b)
{
if (b.length() > a.length())
{
return true;
}
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> v;
for (int i = 0; i < 3; i++)
{
cout << "enter word " << i + 1 << ": ";
string word;
getline(cin, word);
v.push_back(word);
}
sort(v.begin(), v.end(), SortBylength);
cout << "sorted words by length: ";
copy(v.begin(), v.end(), ostream_iterator<string>(cout, " "));
cout << endl;
system("Pause");
return 0;
}
Refining tayspen's example a bit ( i hope he doesn't mind):
private bool IsNumeric(string input)
{
bool isNum = true;
try
{
int.Parse(input);
}
catch
{
isNum = false;
}
return isNum;
}
Or just put that code into a try/catch block and output the error message or a custom message
// generate exception
catch (DivideByZeroException e)
{
// handle exception
}
well, to make registry access read only you could log into your windows without admin rights :P
another thing maybe would be to store that data in a file and fiddle with the security rights of it (right click file -> choose security tab) and modify these to have some (password protected) user have full rights on these and the rest (including you) have only read access :S
On the other hand what you wanna do there sounds quite impossible cause the currenty logged in user (which has the rights to install the application) will also have the corresponding file access rights on his system, maybe you wanna consider proctecting your file by some system driver, that monitors access to the file and prevents its deletion...
\s+ is a regular expression, the \s means to consider whitespaces and the + means to consider at least 1 occurence or more of them
I thing Microsoft Vista is designed in C#, isn't it?
LOL
string [] split = System.Text.RegularExpressions.Regex.Split(contents, "\\s+", RegexOptions.None);
split is already a string array
StreamReader objInput = new StreamReader("C:\\values.dat", System.Text.Encoding.Default);
string contents = objInput.ReadToEnd().Trim();
string [] split = System.Text.RegularExpressions.Regex.Split(contents, "\\s+", RegexOptions.None);
foreach (string s in split)
{
Console.WriteLine(s);
}
Hi, i tried out your code and it seems to work even with the spaces, however one remark: i don't know if it was your intention to initialize the split variable inside the loop...so keep in mind that it will be overwritten all the time and just keeps the latest 3 values (from the last readline)
Well, honestly i m MCSD.NET and it didn't help me that much getting a job. What they look for nowdaddays is a MS in computer science, wether you code or are at the helpdesk (sad but true).
As for the the 70-315 preparation have a look here, it might help:http://www.testking.com/70-315.htm (only study guide, not the Q+A:P)
Hi, i think you are definitely overcomplicating stuff here:
why don't you write sth like this in the ctor:
_field1 = new string(' ', 20);
Hi, for padding you can use this:
string a = "123";
string b = String.Format("{0,-20}", a);
b is of length 20, containing "123" (padded to the left) and the rest is filled with spaces
Hope, this helped.
Try the Environment.GetCommandLineArgs() method