|
If the loss of type safety doesn't bother you much, you could factor it out into a generic routine like this
private void MarshalToUIThread(Delegate d, params object[] arr)
{
if (this.InvokeRequired)
this.BeginInvoke(d, arr);
else
d.DynamicInvoke(arr);
}
You would then call it like MarshalToUIThread(new AppendTextCallBack(AppendText), new object[]{text});
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I am working on an app and having issues with my DAL and connectivity. Can anyone suggest a site with a sample app which details how to do this?
Guess this might help... using VS.NET2005 in conjunction with SQL2K5
-- modified at 14:37 Monday 5th June, 2006
|
|
|
|
|
Can you should be more specific about the type of problem you are having? You might get more replies that way.
Josh
|
|
|
|
|
I have data access/population of a grid via drag and drop but now I am trying to create a data access layer with provided stored procs to populate grids as opposed to drag and drop. So my issue is creating a DATAAccess class with the SQLConnection to be called by various forms.. then once the SQLConnection is made I need to call storeProc1 for example.
So 1. I need an example of a generic dataaccess class to create the connection
2. be able to call the dataaccess from a from
3. be able to call a stored proc to populate a GRID
|
|
|
|
|
This is basic data access work. You should be able to find tons of samples, snippets, etc. on CodeProject. If all else fails, Google.
josh
|
|
|
|
|
I have 2 objects, one is the form ( form object), the other is an object (updating object) responsible for updating it's local DataTable.
Each of these objects runs in its own thread.
In form object I have a datagrid which is bound to the local table of the updating object.
When I run the program, if I don't disable the grid, it can run only 2 loops. If I disable the grid, I can run some dozens of loops.
If I replace the grid by another control ( combobox for example), the application runs smoothly.
Can you explain me why this happen? Thank you very much.
I suspect this problem relate to the Multi-thread enviroment.
|
|
|
|
|
In Windows a control should only be modified from the thread which created the control. Make sure that you are only touching the grid from the main UI thread. You can check that by inspecting the value of InvokeRequired on the grid. If you are updating the grid from a different thread, be sure to marshal the call over to the UI thread via the BeginInvoke method on the grid.
Josh
|
|
|
|
|
I didn't touch the control. The updating thread update the datatable. And the datagrid is bound to the datatable. That's all.
Then I kiss Ur eyes and thank God we're together
|
|
|
|
|
fan wei fang wrote: Then I kiss Ur eyes and thank God we're together
:->
|
|
|
|
|
I forgot to delete my signature man.
Then I kiss Ur eyes and thank God we're together
|
|
|
|
|
Hi,
I want to convert txtboxvalue (dd/mm/yyyy) as (mm/dd/yyyy).How to do this?
Please help me.
Thanks in advance
|
|
|
|
|
DateTime.ToString has an overload which takes a format string. The .NET docs list the format strings for dates. That should be what you need.
Josh
|
|
|
|
|
One way is this:
string date = "12/05/2006";
DateTime newDate;
if (DateTime.TryParse(date, out newDate))
{
DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
Console.WriteLine(newDate.ToString("MM/dd/yyy", myDTFI));
}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi, this is the code i've been trying to convert from VB6 to C#...Is there any way to avoid reading every field of the struct and reaing the whole thing?
VB6 code:
--------------------------------------------------------
Type Person
sName as String * 12
Age as Byte
Code as Long
End Type
private persons() as Person
Sub LoadData(path As String)
dim hf as long
hf = FreeFile
dim recs as long
dim offset as long
open path for binary access read lock write as #hf
get #hf, 1, recs
get #hf, , offset
if recs > 0
redim persons(1 to recs)
'' Very easy way to retrieve UDT array data
get #hf, offset + 1, persons()
end if
End Sub
C#:
-------------------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
//[StructLayout(LayoutKind.Sequential)]
public struct Person
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
string Name;
byte Age;
int Code;
}
public class PersonReader
{
private Person[] persons;
private void LoadData(string path)
{
Stream fileContents = File.Open(path, FileMode.Open);
BinaryReader binReader = new BinaryReader(fileContents);
int recs = binReader.ReadInt32();
int offset = binReader.ReadInt32();
binReader.BaseStream.Position = offset;
//Something like this should go here:
persons = binReader(...//read till the eof and convert it to Person[] :P
// Instead of a code that reads each data of the struct
binReader.Close();
fileContents.Close();
}
}
|
|
|
|
|
I need code that detects if a program is running and then opens a form.
ex.
You turn on your computer and a program starts to run in the background.
You open the internet and a form from the program that is already running opens with it.
Can anyone help me?
Thanks
Hengy
I like Pie
|
|
|
|
|
You might want to have a Windows Service running in the background, periodically polling Process.GetProcesses to see if a browser has been opened. When it detects a browser has been opened, open your Form. I know that there is some trickiness to getting a Form to appear from a windows service, but there should be an article on CP which explains how to do it.
Josh
|
|
|
|
|
Hi,
How can i sort dates In Ascending which look like this:
20060503
20060604
20080101
The first 4 digits is the year, the 2 after year are the months and the last 2 digits is the day.
It should first put them in an array, sort them and than display them in the console.
Thanks in advance!
|
|
|
|
|
Read each date string into a DateTime object. Put the DateTime objects into an array or some other container which exposes a Sort method (Array.Sort is static). Then loop over the array to print them out.
Josh
|
|
|
|
|
Hi Josh Smith,
Im not that good in programming yet. Do you have a sample code for me?
Thanks in advance!
|
|
|
|
|
Noone is going to write your homework for you.
|
|
|
|
|
How rude!
Like this is my homework :S
Seriously dan, where did you get that idea?
Im not that far yet at school. Im not even the one who's writing all this.
|
|
|
|
|
If it looks like a duck, walks like a duck, and quacks like a duck...
|
|
|
|
|
It's a duck!
|
|
|
|
|
Because of the formats, you can also put them in a List<string> and call .Sort().
|
|
|
|
|
Hi
I need a bit of help.
I have this string: "10 > 8 > 99> 34"
From this string, how can I extract all the numbers?
Basically, when I receive the above string, I want to get every number out of it and do something with that number.
Thanks
|
|
|
|