|
|
First off, I would use a dedicated thread to do the logging. But just in case you don't want that, you should not lock while in the process of saving
List<string> copy = null;
lock(_syncObject) {
_buffer.Add(logMessage);
if ( _buffer.Count > _maxBufferSize) {
copy = _buffer;
_buffer = new List<string>();
}
}
if ( copy != null)
Save(copy);
(you would need to adjust your Save() function as well.
LATER EDIT: you will probably need a second lock for saving, but the main idea is that other threads would not be blocked when the buffer gets full.
Best,
John
|
|
|
|
|
How to resize rows and columns during runtime of a dynamically generated tabellayoutpanel?
|
|
|
|
|
The same way you would for one created at design time.
What part of this is giving you a problem? Is it the mechanics of changing sizes, or finding the control, or what?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am creating my own tabellayoutpanel by inheriting Custom tabellayoutpanel i am able to add columns and rows but not resizing them.
|
|
|
|
|
Have you looked at the TableLayoutPanel.ColumnStyles collection?
Each column style has a SizeType and a Width[^] which is pretty much all you can control.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
When I am studying how to use the built-in Win Form Controls, like TableLayoutPanel (TBLLP), I find this method of study pays off:
1. drop a TBLLP on a Form in a "test" project.
2. set all the design-time properties of the TBLLP: number of rows, columns, their sizes, etc., to reflect the design you are trying achieve at run-time
3. open the 'Program.cs file for the project:
a. look at the code that creates the TBLLP in the 'Program.cs file
b. make notes for future reference on the code you'll need at run-time to set the parameters of the TBLLP's structure, and visual style
4. then, in this same project ... either on the same Form ... or in another ... write the code to create a TBLLP at run-time, and apply what you've learned from studying the design-time code in the 'Program.cs file.
5. when/if you get "stuck:" go back and see if you can use any design-time setting or Property on the TBLLP on the Form to achieve what you want, then study, again, the 'Program.cs file code.
At the same time, you will probably also want to be looking up the various facilities/features/Properites/Methods, etc., the TBLLP exposes in the documentation (on- or off-line help files from MS).
Experiment > observe > analyze > research > perturb/change < repeat until you know what you are doing.
Finally, remember the CodeProject is your friend, and there may be articles here showing you useful information/techniques for using the TBLLP; and, StackOverFlow is also your friend. Just search.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 21-Oct-15 8:28am.
|
|
|
|
|
public partial class WebForm1 : System.Web.UI.Page
{
public static string GetProperty(SearchResult searchResult, string PropertyName)
{
if (searchResult.Properties.Contains(PropertyName))
{
return searchResult.Properties[PropertyName][0].ToString();
}
else
{
return string.Empty;
}
}
protected void Page_Load(object sender, EventArgs e)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=rss,DC=org,DC=au");
DirectorySearcher Dsearch = new DirectorySearcher(entry);
SearchResultCollection results=Dsearch.FindAll();
DataTable dt =new DataTable();
//string colName;
// foreach (SearchResult sResultSet in Dsearch.FindAll())
// {
// ResultPropertyCollection myResultPropColl;
// myResultPropColl = sResultSet.Properties;
// }
foreach (string colName in Dsearch.PropertiesToLoad)
{
dt.Columns.Add(colName,Type.GetType("System.String"));
}
foreach (SearchResult sr in results)
{
DataRow dr = dt.NewRow();
foreach (String colName in Dsearch.PropertiesToLoad)
{
if(sr.Properties.Contains(colName))
{
dr[colName] = (sr.Properties[colName][0]);
}
else
{
dr[colName] = "";
}
}
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
|
|
|
|
|
Step through the code with your debugger to find out what is going on.
|
|
|
|
|
The PropertiesToLoad collection does not have a default value. Since you haven't specified any properties to load, it will load all properties for the entries it finds, but the PropertiesToLoad collection will remain empty.
As a result, your DataTable will contain no columns, and the GridView will not display anything.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Help Please,
Am working on a small application to create and dial vpn connection, route ip address and open windows remote application so users do not go thru these steps manually.
Everything is working well until i connect to rdp after the command connect i don't see anything in that window.
axMsRdpClient92.Server = "DOMAIN";
axMsRdpClient92.UserName = "user";
axMsRdpClient92.AdvancedSettings7.ClearTextPassword = "Pass";
axMsRdpClient92.OnConnected += (_1, _2) => { axMsRdpClient92.RemoteProgram.ServerStartProgram(@"C:\Pims2\Pims2.exe", @"pims2 oam.pms c:\couvent", @"C:\Pims2", true, "", true); };
axMsRdpClient92.AdvancedSettings7.RDPPort = 3389;
axMsRdpClient92.AdvancedSettings7.RedirectDevices = true;
axMsRdpClient92.AdvancedSettings7.RedirectPorts = true;
axMsRdpClient92.AdvancedSettings7.GrabFocusOnConnect = true;
axMsRdpClient92.AdvancedSettings7.RedirectPrinters = true;
axMsRdpClient92.Connect();
|
|
|
|
|
string username = "";
string password = "";
{
System.Diagnostics.Process.Start(@"\\"folder path"\ foldername");
}
This is my code. How should I access to server. there is username and password for the server.
Could anyone help me??
|
|
|
|
|
Pick either the forums or QA - but don't post in both.
Posting exactly the same thing in multiple places justs wastes our time and duplicates work - particularly when the question is too vague to answer in the first place!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
was thinking about my upcoming school project focused on Windows 10 universal apps and I ran into very interesting experiment : http://gregtatum.com/poems/stochasticity/1/
I want to work on something very similiar or achieve similar level of animation in universal application writen in Csharp Win2D. I have never worked with any sort of animation or 2d graphics while writing UWA.
Can somebody direct me into right way to start with this ? What are your recommendations...any particular sample codes ?
Thank you.
|
|
|
|
|
Hi everyone,
I am learning delegates at the moment. I am trying to implement a keylogger for fun (found online)! Other examples work fine, but here I am lacking experience. However it seems, the method HookFunc is never reached.
I call it in the main method with
KeyboardHook keylogger = new KeyboardHook();
Shouldnt Install() give me output in the command box in the HookFunc method?
My Code:
public enum VKeys
{
KEY_0 = 0x30,
}
public KeyboardHook()
{
Install();
}
private delegate IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, IntPtr lParam);
private KeyboardHookHandler hookHandler;
public delegate void KeyboardHookCallback(VKeys key);
#region Events
public event KeyboardHookCallback KeyDown;
public event KeyboardHookCallback KeyUp;
#endregion
private IntPtr hookID = IntPtr.Zero;
public void Install()
{
hookHandler = HookFunc;
hookID = SetHook(hookHandler);
}
public void Uninstall()
{
UnhookWindowsHookEx(hookID);
}
private IntPtr SetHook(KeyboardHookHandler proc)
{
Console.WriteLine("HookID: " + hookID.ToString());
using (ProcessModule module = Process.GetCurrentProcess().MainModule)
return SetWindowsHookEx(13, proc, GetModuleHandle(module.ModuleName), 0);
}
private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
{
Console.WriteLine("HookID 2: " + hookID.ToString());
if (nCode >= 0)
{
int iwParam = wParam.ToInt32();
if ((iwParam == WM_KEYDOWN || iwParam == WM_SYSKEYDOWN))
if (KeyDown != null)
KeyDown((VKeys)Marshal.ReadInt32(lParam));
int vkCode = Marshal.ReadInt32(lParam);
if ((iwParam == WM_KEYUP || iwParam == WM_SYSKEYUP))
if (KeyUp != null)
KeyUp((VKeys)Marshal.ReadInt32(lParam));
vkCode = Marshal.ReadInt32(lParam);
}
else
{
;
}
return CallNextHookEx(hookID, nCode, wParam, lParam);
}
|
|
|
|
|
There are several articles (with usable code) here on CodeProject on implementing "Global Hooks" in .NET. Just search. George Mamaladze's article on this is a "CodeProject Classic," having been updated many times over several years: [^].
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hello together,
I'm trying to implement my own IFormatProvider class.
Here are two examples:
-String.Format() - works correctly as expected
-int.ToString() - doesn't work as expected!
Below is the code:
- FormatProvider for the format method:- FormatProvider für die Format-Methode:
public class FormatProviderFormat : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
else
{
return null;
}
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
switch (format)
{
case "A":
return "AA";
case "B":
return "BB";
default:
return "CC";
break;
}
}
}
- The call:
DateTime dt = DateTime.Now;
IFormatProvider fpFormat = new FormatProviderFormat();
Console.WriteLine(String.Format(fpFormat, "{0:A} {0:B} {0}", dt));
- The output (makes no sense, but works as expected):
AA BB CC
Now to the problem:
-Format provider for ToString():
public class FormatProviderToString: IFormatProvider, IFormattable
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(IFormattable))
{
return this;
}
else
{
return null;
}
}
public string ToString(string format, IFormatProvider formatProvider)
{
switch (format)
{
case "A":
return "AA";
case "B":
return "BB";
default:
return "CC";
break;
}
}
}
- The call:
int i = 123;
IFormatProvider fpToString = new FormatProviderToString();
Console.WriteLine(i.ToString("A", fpToString) + " " + i.ToString("B", fpToString) + " " + i.ToString(fpToString));
- The output:
Exception 'format specifier which invalid."
I don't understand what I am doing wrong.
Do you have a tip, an example or a corrected version for me?
Thanks for the help.
I'm a german Speaker. I hope you understand my question.
Regards, Manfred
modified 17-Oct-15 13:52pm.
|
|
|
|
|
Hallo Manfred,
dieses ist ein englisches Forum. Du solltest deinen Post editieren, um deine Fragen zu übersetzen.
This is an English forum. To get help you should edit your post and translate your question.
|
|
|
|
|
First, this is an English speaking site. You would have easily figured that out just by looking around.
From Bing Translate:
Quote: Hello together,
I'm trying to implement your own IFormatProvider.
Here are two examples:
-String.Format() - works correctly as expected
-int. ToString() - doesn't work as expected!
Below is the code:
-FormatProvider for the format method:
Quote: The call:
Quote: The output (makes no sense, but works as expected):
Quote: Now to the problem:
-Format provider for ToString():
Quote: The output:
Exception ' format specifier which invalid. "
I don't understand what I am doing wrong.
Has a tip, an example or a corrected version me someone?
Thanks for the help. Regards, Manfred
|
|
|
|
|
I'm not sure what are you trying to achieve with this piece of code:
int i = 123;
IFormatProvider fpToString = new FormatProviderToString();
Console.WriteLine(i.ToString("A", fpToString) + " " + i.ToString("B", fpToString) + " " + i.ToString(fpToString));
What kind of output you do expect: AA BB 3 ?
I'd suggest to read this: Formatting Types in the .NET Framework[^]
|
|
|
|
|
I have a bindinglist then i store the indexes to dictianary<int, int=""> for fast access to the bindinglist.
then i have something like this
var dIndex = new Dictionary<int, int>()
now i face a problem when removing the item in the bindiglist, because the indexes stored in the dictionary doesnt correspond anymore in the bindinglist.
so my solution is to re-arrange the indexes.
Then i got this.
int id = thisObject.ID;
if(dIndex.ContainsKey(id))
{
data.RemoveAt(dIndex[id]);
_dIndex.remove(id);
foreach(var key in dIndex.keys)
{
if(dIndex[key] > id)
{
dIndex[Key]--;
}
}
}
If I am correct, rearranging the index (the value of the dictionary) using the foreach loop above could result to an O(n).
could anyone here can give me much better solution than this.
I will appreciate for any advice.
Thank you.
|
|
|
|
|
I suggest you use a direct reference to the object(s) in the Binding List for the Value field of the generic Dictionary, rather than an index to their position in a List; since what you will actually store is a pointer, this will not consume much more memory than storing an Int16, or Int32.
In my mind, that also raises the question of why use a List when you are using a Dictionary ... however, I can't see your code, and don't know in what other ways you may be using the List.
private Dictionary<int, BindingListObject> IDToBindingListObject = new Dictionary<int, BindingListObject>();
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Yes you are right, i use the dictionary as pointer to the object, I used the key as the object id and the value as the pointer to the object. I will also use the bindinglist as a datasource. For my first implementation I am aware that it has a memory penalty, and need much more work.
I got just worried about this line of code, how would it impact the performance.
foreach(var key in dIndex.keys)
{
if(dIndex[key] > id)
{
dIndex[Key]--;
}
}
I think the remove(object) method of bindinglist has already been optimized by MS.
Thank you for your suggestion, Ill try it. I think there is no way to achieve O(1) for deleting object on the bindinglist.
|
|
|
|
|
I have created X number of ComboBoxes (PartNo) dynamically, that depending on the number selected in it, it will pull/populate some textboxes with Part Information.
All boxes have been given a Key value of cboBox1, cboBox2, etc.
How can I make an event for these comboboxes?
private void cboBox1_SelectedIndexChanged(object sender, EventArgs e)
Not sure if it matters, but the comboboxes are all part of a panel (pn), so maybe it would be?
private void pn.cboBox1_SelectedIndexChanged(object sender, EventArgs e)
I hate not knowing what I don't know.
|
|
|
|
|
Get a reference to the combo box and use, e.g.
SomeComboBox.SelectedIndexChanged += SomComboBox_SelectedIndexChanged;
Where SomeComboBox is the name of your combo box reference, e.g. cboBox1.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|