|
Sigh. WTF is it with you?
Is it absolute gospel? NOOOOO! Should a nested loop be your first port of call for high-performance code? Again, NOOOOOO! Is it possible that you don't have a choice have to use a nested loop in high-performance code? YESSSSSS!
Happy now?
Loops are only one specific case of performance issues in code. I NEVER said it was the only reason for performance issues.
|
|
|
|
|
You had forgotten to flag your post as "Super sensitive matter! No critical remarks or alternate opinions, please!"
If you do that next time, I will of course leave your post totally uncommented (and as soon as I discover the flag: unread).
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Well, it's obvious my one small tip offended your sensibilities, so be offended all you want.
|
|
|
|
|
A bit late to the party, but here are a few thoughts.
String manipulations are as you say possibly the most likely bottleneck. Strings are immutable in C# (they don't change), so if you concatenate two strings it involves copying the data from both of them into a new string. If you're doing this in a tight loop there's going to a lots of work (and garbage collection) involved. For building up strings, StringBuilder is the class of choice, and for substrings etc. you could look at Span<char> s (C# - All About Span: Exploring a New .NET Mainstay | Microsoft Learn.
If your files are large, take a streaming approach. For instance File.ReadAllLines() loads everything into memory where as File.ReadLines() returns an iterator where you just deal with the current line. Reading a massive file into memory often isn't a great idea.
With those in place, the only other thing I can think of is pipelining. Have one thread read the input file and present records via a queue to a processing stage which processes them and then submits them via a queue to a writing stage. All these stages can run concurrently. TPL dataflow is the thing for this.
Finally, if you are using Parallel processing for nested loops, make sure you do it on the outer loop. There is overhead in parallelising work and you get better performance that way.
It's all rather difficult to say without seeing the code!
Regards,
Rob Philpott.
|
|
|
|
|
Good stuff.
A simple poor man's parallelization might be to spin off worker threads which each handle a different segment of the CSV file... Like a 1000 line file spins off 10 threads handling 0-99:100-199:200-299 etc
How simple it is might be not at all though if what you need to do in parsing is actually also calculate things across ALL rows. Still totally possible/beneficial, just more difficult.
|
|
|
|
|
Steves Smith wrote: I suspect the string operations might be the bottleneck
Programmers are not good at guessing.
That is why, as a different poster said "profile".
That involves instrumenting your code and then running it. The instrumentation measures the process so there is no longer any guessing.
Profiling involves two criteria: time and count
Both are important. A method that runs one time and takes 5 minutes is different than a method that runs 300 times and takes one second (which is also 5 minutes.)
You can instrument your code manually or find a tool (free or not) that does it for you.
|
|
|
|
|
how to get repository user list and and user group from Azure DevOps
arjun
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your question as the search term gave a shed-load of responses: how to get repository user list and and user group from Azure DevOps - Google Search[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you think that Google always, without exception, provides useful, easily understandable guidance for a person who is new to a problem area, then you have only asked Google to be reminded of answers you already know.
I have several times done serious attempts at deciphering hieroglyph explanations provided by Google, without success. Even if I tell about my googling efforts, I have had people yell back to me "Why don't you just f*** google it???" To satisfy that kind of "helpers", I would have to spend twice as much space on all details of my googling as on explaining the problem.
And honestly: I believe that those spending energy on shouting "Google it!" would never spend energy on providing truly helpful assistance.
When, in meatspace, I ask coworkers or friends for help with something, some information I need, they never yell back at me: "Google it!" They treat me as a friend in need of help, not as a misbehaved child.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Hello everyone,
After attempting to create a Telegram project capable of downloading videos either directly sent to the bot or through a Telegram link in the format (https://t.me/channelname/postid), I initially utilized the Telegram Bot API. I managed to fetch updates sent to the bot I created, retrieve the video's file ID and caption, and download the video with the caption as its name. However, I encountered a size limit issue (20 MB).
Subsequently, I learned that another API, the MTProto Telegram API, does not impose a size limit. I created the application and obtained the API ID and API hash. Although I downloaded the "telenet" project, I couldn't find a function specifically for downloading files. Could anybody provide assistance?
I aim to download either video files sent to the bot or videos contained in Telegram links. I'm willing to share my two projects: the Telegram Bot API and the MTProto API.
Thank you in advance.
Regards
|
|
|
|
|
When it comes to APIs you are much better off starting by talking to the people who created it - the chances that anyone on a random website has used your specific API and notices your question are vanishingly small - the API vendor should provide tech support or at least documentation and if they don't then why the heck are you using it?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello community! 👋
I'm excited to share a free open-source tool I've been working on called AD Sync Manager. If you manage Active Directory and Azure AD synchronization in your environment, this might be useful for you!
https:
AD Sync Manager is designed to help streamline and simplify the AD to Azure AD sync process. It provides an easy way to monitor sync status, get alerted on issues, and manage sync cycles.
With this tool, you can:
View the status of your AD Connect sync cycles
Get notified if delta or initial sync fails
Manually trigger full or delta syncs
Analyze sync errors to identify objects with issues
And more!
It's built with PowerShell so it should be easy to deploy in most AD/Azure environments. I'm actively developing it and welcome any feedback or suggestions.
If you struggle with keeping your on-prem and cloud directories in sync, give AD Sync Manager a try. Let me know if you have any questions - I'm happy to help!
Hopefully this tool saves you some time and headaches. Let me know what you think! 😊
|
|
|
|
|
This is the wrong place to post this as thsi forum is for C# discussions - try the Free Tools Discussion Boards[^] instead.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello all,
I am working on on functionality in which i want to write a c# function which will read XML file from folder.
And it will write .txt file from it and will put it in other folder.
can some one help me to do this, when i am reading XML file line by line i should able to write any error or log in log file, if some thing is wrong it should rollback all file else generate .txt file.
Needs to implement it using any design pattern.
|
|
|
|
|
Technically, an XML file is already a text file. All you need to do is change the file extension.
Now, if you actually want to transform the XML in some way, then you're going to need to either write code to do it, or write an XSLT transform[^] to do it.
But since you've provided precisely zero details about the input and expected output, nobody can possibly help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There are several tools for reading an arbitrary XML file into a DOM tree. Use that, rather than reading XML line by line.
This is a plain tree that can easily be traversed like any other tree, usually with a recursive procedure. Depending on the data in the tree and your requirements for the result, you do the traversal depth first or breath first. When you find some value that appears to be text of the kind you are after, you write that to your text output file and continue the search.
Maybe there XML structure contains non-text information that you should nevertheless interpret, and produce the appropriate output. E.g. if a node is flagged as a h1, you will probably want to add an extra blank line above the heading text.
Religious freedom is the freedom to say that two plus two make five.
|
|
|
|
|
Member 12116052 wrote: XML ... put it in other folder.
1. Read and process the XML
2. Determine the output.
3. Open the output file
4. Write 2 to the file from 3.
Member 12116052 wrote: when i am reading XML file line by line i s
Nope. Bad idea.
You do not read XML 'line by line'. Rather you parse it. And then extract values from what you parsed.
If and ONLY if the source of the XML can be guaranteed to be an automated single source, then you can roll the dice and attempt to write your own parser (not an XML parser) which can parse individual lines. Thus skipping the XML learning curve.
And also making your code sure to break if the format of the XML changes.
|
|
|
|
|
To add to what the others say, you need to sit down and work out exactly what you expect to generate form your XML data.
The reason being that XML is a text-based hierarchically structured data format, and it can be all in a single line: newlines (or any other whitespace) are not required by the XML specification, and "individual items" in XML can span multiple lines of text without any change in the data it encapsulates or an entire array of objects can occupy a single line of text - that's problem number one!
The second problem is that the data contained in the XML itself doesn't "lend itself" to a flat file output - which is what an unformatted text file contains.
If you look at a "basic XML" file like this example: W3Schools CD Catalog[^] you can see that what it contains isn't readily useful as a text file unless you actually convert that to a formatted file of some form. Just stripp[ing out the XML stuff doesN't give you any useful data:
Empire BurlesqueBob DylanUSAColumbia10.901985Hide your heartBonnie TylerUKCBS
Records9.901988Greatest HitsDolly PartonUSARCA9.901982Still got the bluesGary
MooreUKVirgin records10.201990ErosEros RamazzottiEUBMG9.901997One night onlyBee
GeesUKPolydor10.901998Sylvias MotherDr.HookUKCBS8.101973Maggie MayRod
StewartUKPickwick8.501990RomanzaAndrea BocelliEUPolydor10.801996When a man loves a
womanPercy SledgeUSAAtlantic8.701987Black angelSavage RoseEUMega10.9019951999 Grammy
NomineesManyUSAGrammy10.201999For the good timesKenny RogersUKMucik Master8.701995Big
Willie styleWill SmithUSAColumbia9.901997Tupelo HoneyVan
MorrisonUKPolydor8.201971SoulsvilleJorn HoelNorwayWEA7.901996The very best
ofCatStevensUKIsland8.901990StopSam BrownUKA and M8.901988Bridge of
SpiesT'PauUKSiren7.901987Private DancerTina TurnerUKCapitol8.901983Midt om nattenKim
LarsenEUMedley7.801983Pavarotti Gala ConcertLuciano PavarottiUKDECCA9.901991The dock of
the bayOtis ReddingUSAStax Records7.901968Picture bookSimply RedEUElektra7.201985RedThe
CommunardsUKLondon7.801987Unchain my heartJoe CockerUSAEMI8.201987 (I manually added the line breaks to prevent that showing as a single very long line!)
So you need to work out what is in the XML that you are interested in, and how you will "present" that in your resulting file - otherwise it's just a waste of your time and effort!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
MyPluginDllClass
{
MyClass _myClass {get; set} = new(this);
public MyPluginDllClass
{
}
public void Test1()
{
}
}
public MyClass
{
MyPluginDllClass _instanceMyPluginDllClass;
public MyClass(MyPluginDllClass param)
{
_instanceMyPluginDllClass = param;
}
public void Test2()
{
_instanceMyPluginDllClass.Test1();
}
}
Hello,
for being able to see all properties in the UI of MyPluginDllClass I would have to instantiate MyClass
as shown above in the properties area of MyPluginDllClass as follows:
MyClass _myClass {get; set} = new(this);
But this does not work, "this" seems to be unknown at this moment in time.
The goal is to use all member functions and properties of MyPluginDllClass within MyClass and to make all properties of MyClass visible in the property grid of the UI of the main application.
Any Ideas, hints what I am doing wrong or why this is the case.
I do not have access to the code of the main application.
MyPluginDllClass ist the interface to the main application.
|
|
|
|
|
You can't use new(this) in a property initializer as the initializer would require the whole object to be initialised by that point, and that cannot be the case because the constructor has not been called yet. And obviously, the constructor can't be called until all property and field initializers are complete!
So you would end up with a deadlock: the instance can't be created because to create the instance you need access to the fully constructed instance!
What you can do is move the initializer to the constructor:
public class Bar
{
public Bar(Foo foo) { }
}
public class Foo
{
public Bar bar {get; set;}
public Foo ()
{
bar = new(this);
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
While I appreciate all the syntactic shortcuts Anders and friends are giving us in the C# language, I feel it's getting a bit ridiculous. We're quickly approaching a point where the shortcuts are making the code unreadable and harder to understand for noobs in favor of making it faster to type.
I suspect the new shortcut is giving the OP trouble in understanding what's going on.
|
|
|
|
|
I agree - the same thing happened to C++ to the point where it's almost unreadable now.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
LOL. I think that's the primary reason why I don't do C++ anymore. That and someone has to pick up my code and maintain it after I'm gone and it's easier to find a C# dev (or Java dev we can convert) than it is to find a C++ dev for the team I'm on.
|
|
|
|
|
Is there a way to exclusively identify email-enabled public folders using Microsoft.Office.Interop.Outlook? EWS or PowerShell should not be used. The program should run on the workstation and utilize the installed Outlook.
Once I've found an email-enabled public folder, I should list the emails contained within it.
So far, I'm encountering difficulties. For instance, I have the following method:
static void ListPublicFolders(Outlook.Folder? folder, string indent)
{
if (folder != null)
{
foreach (object obj in folder.Folders)
{
if (obj is Outlook.Folder)
{
Outlook.Folder? subFolder = obj as Outlook.Folder;
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
{
Outlook.MAPIFolder? parentFolder = subFolder.Parent as Outlook.MAPIFolder;
string parentName = parentFolder != null ? parentFolder.Name : "Parent folder not found";
Console.WriteLine($"{indent}- {subFolder.Name}: {parentName}");
if (parentFolder != null)
{
Marshal.ReleaseComObject(parentFolder);
}
}
ListPublicFolders(subFolder, indent + " ");
if (subFolder != null)
{
Marshal.ReleaseComObject(subFolder);
}
}
}
}
}
The query
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
fails because subFolder.DefaultItemType returns the value Outlook.OlItemType.olPostItem, even though the public folder was set up as an email-enabled folder in Exchange.
Specifically, this is in Microsoft 365. In the Exchange admin center, when creating the folder, I explicitly checked the box for "Email-enabled." This action resulted in two additional options: "Delegation" and "Email properties." In "Email properties," I can specify an alias and a display name. By default, both fields are set to "Orders." Now, I expect the public folder to be email-enabled, with the email address orders@domain.tld.
I don't understand why Outlook is treating the folder incorrectly (I can only create posts and not send emails).
Perhaps someone can help me figure this out.
Thank you and best regards,
René
|
|
|
|
|
Hi All,
Stupid Question time. If a value is read to a textbox it is a String, to convert it to a value in the past I have done:
int Value = 0;
Value = Convert.ToInt16(textBox1.Text) I'm sure of it and then done maths and operations on the Value such as:
if(Value > 1000)
{
MessageBox.Show("Here!");
} But it won't run in VS2022 it returns a System.Format.Exception error. What have I done?
Glenn
modified 9-May-24 10:29am.
|
|
|
|