|
first confirm whether your timer is starting or not some times timer itself does not starts and people start messing with the code inside timer tick event handler
|
|
|
|
|
First off all, you are dealing with deprecated method (mouse_event).
Second, I think you will need KeyPreview enabled/set to true for your form (look on Form1 properties).
Third, "if (e.KeyCode.ToString() == "F") ;" wtf?
That "if" branch statement does nothing, why? You assigned it to empty (;) and by not using "{" and "}" it basically mean "if" is limited to single line.. code style..
Fourth, your if statement comparison should be made from "e.KeyCode.ToString() == "F" to "e.KeyCode == Keys.F".
Fifth, are you sure your events (timer1_Tick/Form1_KeyDown) are assigned, that could be a main cause, "this code does nothing", as I don't see anything in your constructor, "InitializeComponent();", and you didn't posted code of your (*.Designer.cs) Form1.Designer.cs file in this case.
Sixth, it is a lot of bad practice in here so I will jump to seventh.
Seventh, you can't just copy/paste into C# always double-check everything such as Win32 native API you deal with, it maybe have wrong signature from my experience there are a lot of examples also 90% of all Windows native APIs from pinvoke.net are NOT correctly defined, so sad...
I have fixed your code, and it works fine for me, all you need to do is keep up with my friendly warnings.
If you are not that smart, well, here is my smart suggestion for you, why not do:
"timer1.Enabled = Keys.F;" in Form1_KeyDown event (Keys.F will be 1/true when hold down; otherwise 0/false).
And yeah, do not forget mouse_event() is deprecated method and is no longer officially supported (so I should not be even giving you away these nice warnings).
Switch to SendInput function with structures, it is not that hard.
Best regards, OmegaExtern.
modified 17-Aug-14 2:55am.
|
|
|
|
|
Thanks a lot. As you can tell, I know almost nothing. I'm just trying to pick up on the basics by trying to make things.
|
|
|
|
|
Re-Edited my post, refresh your page.
I glad I can help you 
|
|
|
|
|
i have a function which returns a string array. the array may or may not have value.
how to check if the array has any value. In the below code how to check in if codition.
i want to keep the looping option as last. I would like to check in 1 line statement.
I tried indexof, contain and exits option but all of them are for checking a specific value in array and not to check the whole array if it has any value presence.
below is the sample code.
main()
{
string[]victory=war();
if(victory as any value except null) then
{
}
else
{
}
}
public string[] war()
{
step 1.....
return some string array
}
|
|
|
|
|
|
|
Try:
if (victory != null && victory.Length > 0)
{
...
}
You looking for sympathy?
You'll find it in the dictionary, between sympathomimetic and sympatric
(Page 1788, if it helps)
|
|
|
|
|
I have implemented a backgroundworker which simulates a turn in a game I have created:
try
{
GameObjectHelpers.SimulateTurn();
}
catch (Exception ex)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(AppSettings.getCommonApplicationDataPath() + "\\log.log");
file.WriteLine("{0}: {1} {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), ex.StackTrace);
file.WriteLine(ex.Message);
file.Close();
}
My problem is that the message from the exception is not very useable:
8/15/2014: 5:25 PM at Model.GeneralModel.Helpers.GameObjectHe lpers.DoDailyUpdate()
at Model.GeneralModel.Helpers.GameObjectHe lpers.SimulateTurn()
at Model.GeneralModel.Helpers.WorkersModel .GameObjectWorker.bw_DoWork(Object sender, DoWorkEventArgs e)
Is there a better way of catching and logging the exception?
|
|
|
|
|
What is the message from the exception?
|
|
|
|
|
It is just:
at Model.GeneralModel.Helpers.GameObjectHe lpers.DoDailyUpdate()
at Model.GeneralModel.Helpers.GameObjectHe lpers.SimulateTurn()
at Model.GeneralModel.Helpers.WorkersModel .GameObjectWorker.bw_DoWork(Object sender, DoWorkEventArgs e)
|
|
|
|
|
That's the stack trace not the message. Unless you know what exception has been caught the stack trace is not much use.
|
|
|
|
|
Yes, by logging all the information of the exception, not just part of it. Simlpy use "Exception.ToString()" and log those results. It will include the message (if any), a stacktrace (that tells you where the exception came from), and the message type, which is now missing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You know there are logging libraries that already handle all of what you are attempting to do within a catch block?
And never attempt to handle an exception in a catch/finally block with code that can also throw an exception. (Files can throw exceptions.)
|
|
|
|
|
I didn't knew that but I will try to look into it
|
|
|
|
|
Hi,
Kindly note that, while capturing network incoming tcp packets using following codes/methods, missing some packets. It is sure that all packets all coming on my network perfectly fine but unfortunately I am missing some packets. Please let me know, what and where, I am doing mistake in my following mentioned codes.
Thank you & Regards
(Riaz)
public void Capture()
{
_mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
_mainSocket.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.10"), 0));
var byTrue = new byte[] { 1, 0, 0, 0 };
var byOut = new byte[] { 1, 0, 0, 0 };
_mainSocket.IOControl(IOControlCode.ReceiveAll, byTrue, byOut);
_mainSocket.EnableBroadcast = true;
_mainSocket.BeginReceive(_data, 0, _data.Length, SocketFlags.None, OnReceive, null);
}
private void Parse(byte[] data, int size)
{
ipH = new IPHeader(data, size);
if (ipH.ProtocolType == Protocol.TCP)
{
FilterData(data, size);
}
System.Threading.Thread.Sleep(5);
}
private void FilterData(byte[] data, int size)
{
}
|
|
|
|
|
Don't you think that by putting your thread to sleep that you're killing your performance for no reason? 5 milliseconds can be an eternity in the view of a packet.
Also, packets can arrive so fast that you're not going to be able to process them at the same speed that they show up. You really need to have a FIFO buffering system between the receive code and the Parse/Filter code.
|
|
|
|
|
thanks for your suggestion
|
|
|
|
|
Interesting bit of code, although the implementation of OnReceive is not shown. The code suggest that your packets are TCP, so why are you not specifying that when you create the socket?
When I do this sort of thing (in TCP), I normally listen on a socket and accept connections, so I'm not sure what's going on here.
One possibility is that your code is not keeping up with the incoming packets, especially with the 5ms sleep that Dave points out. You could try increasing the receive buffer on the socket to test this assertion. And definitely get rid of the sleep.
If you update your code with the pertinent OnRecieve, that would provide more clues.
Regards,
Rob Philpott.
|
|
|
|
|
thanks for your suggestion
|
|
|
|
|
Hi all
why does this form freeze when I press the strtChatBtn at the second time?
Server Form Class
public partial class Server_Design : Form
{
Thread serverStart;
private bool btnStartStop = true;
public Server_Design()
{
InitializeComponent();
}
private void Server_Design_Load_1(object sender, EventArgs e)
{
}
private void strtChatBtn_Click(object sender, EventArgs e)
{
if (btnStartStop)
{
serverStart = new Thread(new ThreadStart(Connection.StartListen));
serverStart.Start();
strtChatBtn.Text = "Stop Chat";
btnStartStop = false;
}
else
{
this.serverStart.Abort();
Connection.StopListen();
strtChatBtn.Text = "Start Chat";
btnStartStop = true;
}
}
}
}
Connection Class
public static class Connection
{
static IPAddress srvIP = IPAddress.Parse("127.0.0.1");
static int srvPort = 8888;
static TcpListener server = new TcpListener(srvIP, srvPort);
public static void StartListen()
{
server.Start();
while (1 != 0)
{
TcpClient client = server.AcceptTcpClient();
NetworkStream ns = client.GetStream();
StreamWriter sw = new StreamWriter(ns);
StreamReader sr = new StreamReader(ns);
ns = client.GetStream();
client.Close();
ns.Close();
sw.Close();
sr.Close();
}
}
public static void StopListen()
{
server.Stop();
}
}
}
|
|
|
|
|
I don't know, but it's generally not a good idea to use Abort. Try using a semaphore instead.
bool listen = false ;
Before starting the thread, set the semaphore to true .
In the thread use while ( listen )
Before stopping, set the semaphore to false , then use this.serverStart.Join to wait for the thread to exit.
http://msdn.microsoft.com/en-us/library/95hbf2ta(v=vs.110).aspx[^]
|
|
|
|
|
I want to generate summary report in GridView.
my database raw table is:
Table1
id userID feedBack timeStamp
1 user1 Excellent 2014-08-07 14:50:22.000
2 user2 Average 2014-08-07 14:50:42.000
3 user3 Good 2014-08-07 14:51:20.000
4 user4 Poor 2014-08-07 14:55:25.000
5 user1 Good 2014-08-07 14:57:02.000
based on that database table.
I want to show summary report in GridView as follow.
Report1
Input: DateRange
UserID Excellent Good Average Poor
user1 1 1 0 0
user2 0 0 1 0
user3 0 1 0 0
user4 0 0 0 1
that is , what I want to show in GridView .
it is more clear so that you friends can help me.
regards
modified 15-Aug-14 4:16am.
|
|
|
|
|
You need to use a PIVOT query on the data
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Oh Oh wait a chance for self promotio[^]n
Never underestimate the power of human stupidity
RAH
|
|
|
|