1000000 / 55.9MB / 13.2GB
2000000 / 111.6MB / 25.2GB
100000 / 8.1MB / 4.1GB
200000 / 16.1MB / 8GB
300000 / 24.2MB / 11.9GB
400000 / 32.2MB / 15.7GB
500000 / 40.3MB / 19.5GB
100000 / 10.5MB / 6.6GB
200000 / 21MB / 13.1GB
300000 / 31.5MB / 19.5GB
400000 / 42MB / 25.8GB
100000 / 13MB / 9.1GB
200000 / 25.9MB / 18.1GB
300000 / 38.9MB / 27GB
static Random rnd = new Random();
static string[] GenStrings(int cnt, int strLen)
{
string[] arr = new string[cnt];
var i = 0;
while (i < cnt)
{
var sb = new StringBuilder();
for (var j = 0; j < strLen; j++)
{
sb.Append(rnd.Next(0, 256));
//sb.Append(TAbc[rnd.Next(0, TAbc.Length)]);
}
arr[i++] = sb.ToString();
}
return arr;
}
var arraySize = 300000;
var stringSize = 20;
var GCStartArr = GC.GetTotalMemory(true);
var strings = GenStrings(arraySize, stringSize);
var GCEndArr = GC.GetTotalMemory(true);
var GCStart = GC.GetTotalMemory(true);
var tree = new ArrayTree<string>();
foreach (string s in strings)
{
tree.Add(Encoding.UTF8.GetBytes(s), s);
}
var GCEnd = GC.GetTotalMemory(true);
Console.WriteLine("Array x string size / Array memory used / Tree memory used");
Console.WriteLine($"{arraySize} х {stringSize} / {BytesToString(GCEndArr - GCStartArr)} / {BytesToString(GCEnd - GCStart)}");
HttpWebRequest
получилось сделать:HttpWebRequest http = (HttpWebRequest)WebRequest.Create(pathToHtml);
WebResponse response = http.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
string html = sr.ReadToEnd();
// Создание экземпляра локальной переменной «doc».
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
// Загрузка HTML кода в локальную переменную «doc».
doc.LoadHtml(html);
var x = doc.DocumentNode.SelectNodes(pathToHTMLTextNode).Elements("tr").ToList();
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
public static class Program
{
private static string html = "Ошибка";
private static void Main()
{
ShowTags("https://www.yandex.ru/","a");
Console.ReadKey();
}
private static async void ShowTags(string my_url, string tag = "a") // Тег по умолчанию для поиска, ищем теги <a></a>
{
// Загружем страницу
string data = await GetHtmlPageText(my_url);
if (!data.Contains("Ошибка"))
{
string pattern = string.Format(@"\<{0}.*?\>(?<tegData>.+?)\<\/{0}\>", tag.Trim());
// \<{0}.*?\> - открывающий тег
// \<\/{0}\> - закрывающий тег
// (?<tegData>.+?) - содержимое тега, записываем в группу tegData
Regex regex = new Regex(pattern, RegexOptions.ExplicitCapture);
MatchCollection matches = regex.Matches(data);
foreach (Match matche in matches)
{
Console.WriteLine(matche.Value);
Console.WriteLine("Содержание:");
Console.WriteLine(matche.Groups["tegData"].Value);
Console.WriteLine("---------------------------");
}
}
else
{
Console.WriteLine("Ошибка при загрузке со страницы: " + my_url);
}
}
private static async Task<string> GetHtmlPageText(string url)
{
await Task.Run(async()=>{
// ... используем HttpClient.
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(url))
using (HttpContent content = response.Content)
{
// ... записать ответ
string result = await content.ReadAsStringAsync();
if (html != null)
{
html = result;
}
}
});
return html;
}
}
}
<a href="http://mail.yandex.ru"onclick="c(this,17,1080)">Войти в почту</a>
Содержание:
Войти в почту
using ManagedBass;
using System;
namespace Yamux
{
public class Player
{
public static void PlayUrlFile()
{
// Init BASS using the default output device
if (Bass.Init())
{
// Create a stream from a file
var stream = Bass.CreateStream("/home/kirill/Downloads.mp3");
if (stream != 0)
Bass.ChannelPlay(stream); // Play the stream
// Error creating the stream
else Console.WriteLine("Error: {0}!", Bass.LastError);
// Wait till user presses a key
Console.WriteLine("Press any key to exit");
Console.ReadKey();
// Free the stream
Bass.StreamFree(stream);
// Free current device.
Bass.Free();
}
else Console.WriteLine("BASS could not be initialized!");
}
}
}
/**
* выдергивает videoId из url или embed
* тесты здесь: http://jsfiddle.net/1j5do56g/1/
*
* @param string input
* @returns string youtube video id
*/
function youtubeGetID(input){
var r = input.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/)
if(r[2] !== undefined) {
return r[2].split(/[^0-9a-z_\-]/i)[0]
} else {
r = input.match(/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/)
if(r && r[1] !== undefined) {
return r[1]
}
else return input
}
}
// parse and update id
var youtubeId = youtubeGetID(field.val())
field.val(youtubeId)
// update iframe
var newSrc = 'http://www.youtube.com/embed/' + youtubeId
var iframe = field.closest('.panel-body').find('iframe')
iframe.attr('src', newSrc)
using Microsoft.DirectX.AudioVideoPlayback;
private Video video;
private string[] videoPaths;
private string folderPath = @"C:\Users\Dell XPS\Desktop\Videos\";
private int selectedIndex = 0;
private Size formSize;
private Size pnlSize;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
formSize = new Size(this.Width, this.Height);
pnlSize = new Size(pnlVideo.Width, pnlVideo.Height);
videoPaths = Directory.GetFiles(folderPath, "*.wmv");
if (videoPaths != null)
{
foreach (string path in videoPaths)
{
string vid = path.Replace(folderPath, string.Empty);
vid = vid.Replace(".wmv", string.Empty);
lstVideos.Items.Add(vid);
}
}
lstVideos.SelectedIndex = selectedIndex;
}
private void lstVideos_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
video.Stop();
video.Dispose();
}
catch { }
int index = lstVideos.SelectedIndex;
selectedIndex = index;
video = new Video(videoPaths[index], false);
video.Owner = pnlVideo;
pnlVideo.Size = pnlSize;
video.Play();
tmrVideo.Enabled = true;
btnPlayPause.Text = "Pause";
video.Ending += Video_Ending;
lblVideo.Text = lstVideos.Text;
}
private void Video_Ending(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(2000);
if (InvokeRequired)
{
this.Invoke(new Action(() =>
{
NextVideo();
}));
}
});
}
private void NextVideo()
{
int index = lstVideos.SelectedIndex;
index++;
if (index > videoPaths.Length - 1)
index = 0;
selectedIndex = index;
lstVideos.SelectedIndex = index;
}
private void btnNext_Click(object sender, EventArgs e)
{
NextVideo();
}
private void btnPrevious_Click(object sender, EventArgs e)
{
PreviousVideo();
}
private void PreviousVideo()
{
int index = lstVideos.SelectedIndex;
index--;
if (index == -1)
index = videoPaths.Length - 1;
selectedIndex = index;
lstVideos.SelectedIndex = index;
}
private void btnPlayPause_Click(object sender, EventArgs e)
{
if (!video.Playing)
{
video.Play();
tmrVideo.Enabled = true;
btnPlayPause.Text = "Pause";
}
else if (video.Playing)
{
video.Pause();
tmrVideo.Enabled = false;
btnPlayPause.Text = "Play";
}
}
private void btnFullscreen_Click(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
video.Owner = this;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
//exit full screen when escape is pressed
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Normal;
this.Size = formSize;
video.Owner = pnlVideo;
pnlVideo.Size = pnlSize;
}
}
private void trackVolume_Scroll(object sender, EventArgs e)
{
video.Audio.Volume = trackVolume.Value;
}
private void btnVolume_Click(object sender, EventArgs e)
{
trackVolume.Visible = !trackVolume.Visible;
}
private void tmrVideo_Tick(object sender, EventArgs e)
{
int currentTime = Convert.ToInt32(video.CurrentPosition);
int maxTime = Convert.ToInt32(video.Duration);
lblVideoPosition.Text = string.Format("{0:00}:{1:00}:{2:00}", currentTime / 3600, (currentTime / 60) % 60, currentTime % 60)
+ " / " +
string.Format("{0:00}:{1:00}:{2:00}", maxTime / 3600, (maxTime / 60) % 60, maxTime % 60);
}
Встал вопрос об оптимизации данного действия, потому как на обновление таблицы уходит минимум 2 минуты.
using(var reader = sqliteCommand.ExecuteReader())
{
while(reader.Read())
{
// вызов вашего метода для конкретной строчки
}
}
using(var reader = sqliteCommand.ExecuteReader())
{
// вызов вашего метода для reader, где вы будете сами перебирать строчки
}
void Do()
{
DoSmthWithDB((Action<DataReader>)((reader) => {Console.WriteLine(reader[0].ToString());}));
}
void DoSmthWithDB(Action<DataReader> myAction)
{
...
// Создание команды к БД
...
using(var reader = sqliteCommand.ExecuteReader())
{
while(reader.Read())
{
myAction(reader); // Action<DataReader> переданный в виде параметра
}
}
}