|
You should be able to use Join in Go.
1) main thread creates instance of Foo()
2) for (1..1000) Foo.Go() should be a fire and forget unit of work
2.1) Go uses Join to wait until all threads are complete, then exits
3) main thread "exits" , BUT "PROCESS HANGS" until all 1000 units of work are completed
You can't have the main thread exit and "hang" at the same time.
|
|
|
|
|
i want make simple web browser by c# application.the browser i want to set fit to screen as in the image.
|
|
|
|
|
|
thanx Eddy for link..but i want to make browser with zoom out and zoom in facility....can you give me some idea with demo how can i do it...
|
|
|
|
|
Press Ctrl-+, should be supported by the COM-control.
If not, inject a zoom-tag in the body's style-tag.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
can u show me demo...tnx for tht
|
|
|
|
|
No.
Someone else might
|
|
|
|
|
ok thnx for giving ur pricious time....
|
|
|
|
|
I'am trouble to implement encryption testing without times in millisecond and how i adding to the code??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace RSAEncryption
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
#region-----Encryptionand Decryption Function-----
static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] encryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
}
return encryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
{
try
{
byte[] decryptedData;
using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
{
RSA.ImportParameters(RSAKey);
decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
}
return decryptedData;
}
catch (CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
#endregion
#region--variables area
UnicodeEncoding ByteConverter = new UnicodeEncoding();
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
byte[] plaintext;
byte[] encryptedtext;
#endregion
#region-- Function Implemantation
private void Encrypt_Click(object sender, EventArgs e)
{
plaintext = ByteConverter.GetBytes(txtplain.Text);
encryptedtext = Encryption(plaintext, RSA.ExportParameters(false), false);
txtencrypt.Text = ByteConverter.GetString(encryptedtext);
}
private void Decrypt_Click(object sender, EventArgs e)
{
byte[] decryptedtex = Decryption(encryptedtext, RSA.ExportParameters(true), false);
txtdecrypt.Text = ByteConverter.GetString(decryptedtex);
}
#endregion
}
}
|
|
|
|
|
|
I mean, adding one textbox and while to running to the textbox in the timers range 0-2000 millisecond
|
|
|
|
|
|
I mean, adding one textbox and while to running to the textbox in the timers range 0-2000 millisecond
modified 11-Sep-14 7:50am.
|
|
|
|
|
I have an object[]. I need to convert it to IEnumerable T **FAST**.
Right now I have (this part is called ONCE and EnumFactory is cache):
MethodInfo mi = typeof(Enumerable).GetMethod("CastIterator", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(from);
ParameterExpression[] param = new ParameterExpression[] { Expression.Parameter(typeof(object[])) };
EnumFactory = Expression.Lambda<Func<object[], object>>(Expression.Call(mi, param), param).Compile();
Then I call it as (this part is called millions of times):
return EnumFactory(oArray);
Most of the examples you'll see call typeof(Enumerable).GetMethod("Cast"), but if you look at that in reflector, you'll see it does a few useless checks and then calls CastIterator. To save time on the useless checks and the extra method call, I call CastIterator directly.
Any other options? EnumFactory is, of course, cached. If I comment out the part that fills in oArray, its negligible compared to calling EnumFactory. I do not know T at compile time.
|
|
|
|
|
How slow is a simple for -loop ?
private static T[]
CastArray<T>
(
object[] Value
)
{
T[] result = new T [ Value.Length ] ;
for ( int i = 0 ; i < result.Length ; i++ ) result [ i ] = (T) Value [ i ] ;
return ( result ) ;
}
It works with int s, does it work with what you have? This should be your baseline. How much faster is your technique?
I suppose the bigger question is why you have an object array in the first place.
|
|
|
|
|
I don't know T until runtime, so I would have to do the same thing of making a generic method and calling it through a delegate / invoke / expression tree.
However, the above code you suggested will actually be "much" slower then Cast / CastIterator since you are new'ing up the T array every time. CastIterator is simply:
private static IEnumerable<TResult> CastIterator<TResult>(IEnumerable source)
{
foreach (object current in source)
{
yield return (TResult)((object)current);
}
yield break;
}
Unless of course, the yield keyword is expensive... but from my understanding of how it works internally, it should be MUCH, MUCH faster then the method above since its lazy (and it doesn't new up anything).
I know I'm nitpicking lol, but really trying to squeeze everything out of this block of code.
|
|
|
|
|
If you don't know the type until runtime, why not make it IEnumerable<dynamic>. When you run this, it will appear that you have an IEnumerable of objects (as you have now), but with the proviso that because it's dynamic, it will honour any method calls you care to make on that object. I haven't tested the performance of this, but that might be worth a try for you.
|
|
|
|
|
Hmm... I need to return a strongly typed IEnumerable. If I return an IEnumerable<dynamic> off of the object[], it compiles, but I get a runtime cast error. I don't have control over the calling code. I'm just the library that serves it up.
|
|
|
|
|
SledgeHammer01 wrote: will actually be "much" slower
That may be, but unless you try it (and/or the Enumerator you show) you'll never know for sure -- you're only acting on hearsay or prejudice. Get a baseline reading, then try something else and get another reading, etc. You're assuming that what you have is "much" faster, but it may not be, you need metrics.
What are you trying to do?
Why are you accepting an object[] of them; can you correct this upstream?
And what actual types are involved? Value types? Structs? Small simple classes? Large complex classes?
SledgeHammer01 wrote: its lazy
Laziness may not help much unless the consumer doesn't need all the members.
And that cast to object looks redundant.
|
|
|
|
|
PIEBALDconsult wrote: That may be, but unless you try it (and/or the Enumerator you show) you'll never
know for sure -- you're only acting on hearsay or prejudice. Get a baseline
reading, then try something else and get another reading, etc. You're assuming
that what you have is "much" faster, but it may not be, you need metrics.
What are you trying to do? Why are you accepting an object[] of
them; can you correct this upstream? And what actual types are involved?
Value types? Structs? Small simple classes? Large complex classes?
Ok ... well, for the sake of the thread, I did... its not "much, much slower" as I thought it would be... but it is quite a bit slower (about 15%). 3900ms vs 4500ms
What I'm trying to do is given an array of some unknown (at compile time) object (which is why I store them as object[]), I need to convert said object[] into an IEnumerable T where T is known at compile time by the caller of my class.
I could potentially store a T[], but unfortunately, my class has non-T overloads. So its kind of like I need to support:
T GetTheObjects<T>();
IEnumerable<SomeClass> enum = GetTheObjects<SomeClass>();
object GetTheObjects(Type type);
IEnumerable<SomeClass> enum = (IEnumerable<SomeClass>)GetTheObjects(typeof(SomeClass));
If I only had to support the T overloads, I could avoid boxing / unboxing...
PIEBALDconsult wrote: And that cast to object looks redundant.
Agreed. That's how Reflector shows it. I tried c&p'ing that static method into my dll and removing the extra cast, but it didn't affect performance.
|
|
|
|
|
I'm new to C# and am working on first project.
I have a WINFORM that displays a treenode and a datagridview. I want selected items from the treenode to go to the datagridview. If I select the parent node of treenode all children go to datagridview but if I just expand the parent and select one of the children, nothing goes to datagrid. (selection of a treenode fires a method to get attributes of the item from sql table and it is the attributes that go to the grid + node value)
When parent is selected 'if (e.Node.Nodes.Count > 0)' is true. When parent isn't selected but child is 'if (e.Node.Nodes.Count > 0)' is false.
So my question is what code do I need to find child nodes that are checked/unchecked?
Once I get correct code to find child node check, what code moves it to datagrid or delete from datagrid if child is unchecked?
private void getChildNodesToGrid()
{
DataTable dt = getFieldsTable();
dgvColumns.DataSource = dt;
getAttributeSIDs();
}
private void tvFileMan_AfterCheck(object sender, TreeViewEventArgs e)
{
getFileAndColumns();
if (e.Node.Nodes.Count > 0)
{
this.CheckAllChildNodes(e.Node, e.Node.Checked);
e.Node.Expand();
foreach (TreeNode tn in e.Node.Nodes)
{
if (tn.Nodes.Count.Equals(0))
tn.Checked = e.Node.Checked;
}
getChildNodesToGrid();
}
|
|
|
|
|
RESOLVED:
Added an 'else' to the AfterCheck so it simply calls getChildNodesToGrid()
I then updated private DataTable getFieldsTable() to add a counter and condition 'if (fileNode.Nodes[cnt].Checked)'.
Don't know if this is proper programming but seems to work.
private void tvFileMan_AfterCheck(object sender, TreeViewEventArgs e)
{
getFileAndColumns();
if (e.Node.Nodes.Count > 0)
{
e.Node.Expand();
foreach (TreeNode tn in e.Node.Nodes)
{
if (tn.Nodes.Count.Equals(0))
tn.Checked = e.Node.Checked;
}
getChildNodesToGrid();
}
else
{
e.Node.Expand();
if (e.Node.Checked)
{
getChildNodesToGrid();
}
}
private DataTable getFieldsTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ColumnName");
dt.Columns.Add("FMFieldName");
dt.Columns.Add("FMFieldNumber");
dt.Columns.Add("FMFileNumber");
dt.Columns.Add("FMFieldType");
dt.Columns.Add("ResolvedValue");
dt.Columns.Add("PointsToFileNumber");
TreeNode fileNode = tvFileMan.SelectedNode;
int cnt = 0;
foreach (TreeNode tn in fileNode.Nodes)
{
if (tn.Nodes.Count == 0)
{
if (fileNode.Nodes[cnt].Checked)
{
DataRow dr = dt.NewRow();
dr["FMFieldName"] = tn.Text.Substring(tn.Text.IndexOf(" - ") + 4);
dr["FMFieldNumber"] = tn.Tag.ToString();
dr["FMFileNumber"] = tn.Parent.Tag.ToString();
dr["ColumnName"] = suggestName(tn.Text.Substring(tn.Text.IndexOf(" - ") + 4));
if (dr["PointsToFileNumber"].ToString().Length > 0)
{
dr["ColumnName"] = suggestName(tn.Text.Substring(tn.Text.IndexOf(" - ") + 4) + "txt");
}
dt.Rows.Add(dr);
}
cnt++;
}
}
return dt;
}
private void getFileAndColumns()
{
label4.Visible = false;
label5.Visible = false;
btAllFields.Visible = false;
cbComputed.Checked = false;
TreeNode node = tvFileMan.SelectedNode;
if (node == null) return;
if (node.Index == 0) return;
if (node.Nodes.Count > 0)
{
tbFileNumber.Text = node.Tag.ToString();
tbFileName.Text = node.Text.Substring(node.Text.IndexOf(" - ") + 4);
tbTableName.Text = "xxxx." + (suggestName(tbFileName.Text) + "F" + tbFileNumber.Text.Replace('.', 'x'));
label4.Text = "To select all fields push button to the right. \nOtherwise double-click fields to add them one at a time.";
label4.Visible = true;
btAllFields.Visible = true;
dgvColumns.DataSource = null;
dgvPKIENS.DataSource = getPKIENSTable();
getPKIENSIDs();
}
else
{
}
}
|
|
|
|
|
I want to create a simple chat app. I would like to host it on my server and allow one-to-many people to chat.
I'd like to do it myself as a learning experience. Can anyone point me in the right direction?
Thank you
If it's not broken, fix it until it is
|
|
|
|
|
Lots of examples here[^].
/ravi
|
|
|
|
|
LOL - Never thought to look here
DOH!
If it's not broken, fix it until it is
|
|
|
|